I was wondering if there is a way to set a default function for a getter or a setter. For example, let's say I have this:
public class MyClass
{
public bool IsDirty {get; private set; } = false;
private string _property;
public string Property1
{
get
{
return _property1;
}
set
{
if (value != _property1)
{
_property1 = value;
IsDirty = true;
}
}
}
}
I was wondering if there was a way to do something like this:
public class MyClass
{
public bool IsDirty {get; private set;} = false;
MyClass.defaultSet = { if (value != !_property1) { _property1 = value; IsDirty = true; } };
private string _property1;
public string Property1 { get; set; }
public string Property2 {get; set;}
public string Property3 {get; set;}
//...
}
So that I don't have to do it the first way on this big class I have (~100 properties).
No, this doesn't exist, for several reasons:
get
operation on the property itself!), delegates, etcProperty
name, so that part of the method is different. You'd need another keyword or argument to the set method.someBool
/ IsDirty
property.