-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-Language DesignFeature RequestLanguage-C#Resolution-DuplicateThe described behavior is tracked in another issueThe described behavior is tracked in another issue
Description
Proposition
An easy way to implement default constructor that only bind the parameter of class properties
Situation
When you have a class/struct and want to enforce the initialization through constructor we have to do something like this:
public class Access
{
public string Name { get; set; }
public bool IsActive { get; set; }
public Access( // It's obvious that it's the constructos for Access class, is's inside it!
string name, // Have to duplicate the name and type of the property
bool isActive) // Again the name and type of the property
{
this.Name = name; // Obvious associations
this.IsActive = isActive; // Obvious associations
}
}Why not write something like:
public class Access
{
public string Name { get; set; }
public bool IsActive { get; set; }
public(Name, IsActive = true)
}We could even use DataContracts and remove the necessity to validate the parameters, it would be very helpful for creating small helper classes.
public class Access
{
public string Name { get; set; }
public bool IsActive { get; set; }
public([NotNull]Name, IsActive = true)
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-Language DesignFeature RequestLanguage-C#Resolution-DuplicateThe described behavior is tracked in another issueThe described behavior is tracked in another issue