.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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -