.net - Can C# implicit operator's be used to set a property? -
i'm trying use implicit operators make using library, bit easier.
i know can get
value implicitly, not sure how set
value, if can done easily.
here's pseduo code i'm thinking in head ...
public class int32notified : inotifypropertychanged { private int _value; public int value { { return _value; } set { _value = value; onpropertychanged("value"); } } public event propertychangedeventhandler propertychanged; public static implicit operator int(int32notified value) { return value.value; } private void onpropertychanged(string propertyname) { var handler = propertychanged; if (handler != null) { handler(this, new propertychangedeventargs(propertyname)); } } }
and i'm thinking .. when using it....
public class foo { // yeah, i've not wired event... (yet) public int32notified age { get; set; } } ... // creation , setting. var foo = new foo { age = 10 }; // getting int age = foo.age;
is possible?
Comments
Post a Comment