wpf - What kind of compiler magic do we need more? -


i develop lot view models are:

1) have implement inotifypropertychanged bindable ui.

2) property setters have raise propertychanged on change.

3) propertychanged event has provide proper property name.

if (like me) tied of writing this:

 public string name  {      {      return _name;    }   set    {      if (_name != value)      {       _name = value;       raisepropertychanged("name");     }   } }  

then refactor method , forget update property name literal:

 string _fundname; public string fundname  {      {      return _fundname;    }   set    {      if (_fundname != value)      {       _fundname = value;       raisepropertychanged("name");     }   } }  

and spend day debug why ui not refreshing , databinding doesn't work properly.

then need kind of magic.

what if need write this:

 [magic] // implicit transformation public string fundname { get; set; } 

or if have many properties:

 [magic] public class myviewmodel {   public string fundname { get; set; }   public string fundtype { get; set; }    [nomagic] // suppress transformation   public int internalid { get; set; } } 

so have developed msbuild task magic after build (http://kindofmagic.codeplex.com).

the question is, kind of magical postprocessing more?

does automatic implementation of inotifypropertychanging makes sense?

if we're going have fancy code generation, think prefer way generate dependancyproperties more easily. snippit use helpful, i'm not fan how jumbled code looks when have on-changed , coerce callbacks, , metadata options. maybe i'll try , mock sample after work.

edit: well, here's 1 concept. lot more clever if pass anonymous methods attributes, it's still step up.

before:

[dpdefault("the void")] [dpcoerce(new coercevaluecallback(mainwindow.coerceaddress))] [dpchanged(new propertychangedcallback(mainwindow.changeaddress1))] [dpchanged(new propertychangedcallback(mainwindow.changeaddress2))] [dpoptions(frameworkpropertymetadataoptions.inherits)] public string address {     { return dp.get<string>(); }     set {         if (dp.get<string>() != value) {             dp.set(value);             postoffice.sendmailtotheboss("i moved!");         }     } } 

after:

public string address {     { return (string)getvalue(addressproperty); }     set {         if ((string)getvalue(addressproperty) != value) {             setvalue(addressproperty, value);             postoffice.sendmailtotheboss("i moved!");         }     } }  public static readonly dependencyproperty addressproperty =     dependencyproperty.register("address", typeof(string), typeof(mainwindow),         new frameworkpropertymetadata((string)"the void",             frameworkpropertymetadataoptions.inherits,             new propertychangedcallback(mainwindow.changeaddress1)                 + new propertychangedcallback(mainwindow.changeaddress2),             new coercevaluecallback(mainwindow.coerceaddress))); 

typically, 'dpdefault' attribute used, if doesn't make code shorter, makes clearer. here more typical example:

before:

[dpdefault("the void")] public string address { get; set; } 

after:

public string address {     { return (string)getvalue(addressproperty); }     set { setvalue(addressproperty, value); } }  public static readonly dependencyproperty addressproperty =     dependencyproperty.register("address", typeof(string), typeof(mainwindow),         new uipropertymetadata((string)"the void")); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -