-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Type of issue
Missing information
Feedback
In my opinion, the feature:
The hashtable syntax only works for classes that have a default constructor that doesn't expect any parameters. It creates an instance of the class with the default constructor and then assigns the key-value pairs to the instance properties. If any key in the hashtable isn't a valid property name, PowerShell raises an error.
deserves a beter name than hashtable syntax, considering that this feature include more than a "hashtable syntax":
- A runtime conversion (type casting)
- Is not specific to
hashtablesbut alldictionaryobjects and alsoPSCustomObjects - And even recursively converts complete object-graphs derived from e.g. a Json file
(see e.g.: Trying to Deserialize JSON to typed Object in Powershell)
I am not native English, but I think something like the Default PowerShell Constructor would better cover the context.
A result of this feature is that you could use a "hashtable syntax" during design-time to pre-populate its properties
From my view, this feature is not known/understood enough resulting in PowerShell scripters designing there own custom constructors (which less functionality and consistency as e.g. error messages) or even functions around the class/instance to populate the related properties.
Page URL
Content source URL
Author
Platform Id
b1fb7f15-4113-8097-756b-806c3754b04a
Document Id
9bdef14d-66f7-ee94-2ab9-e16bd6bc751e