Automatic INotifyPropertyChanged Implementation through T4 code generation?

后端 未结 3 926
迷失自我
迷失自我 2020-12-06 01:55

I\'m currently working on setting up a new project of mine and was wondering how I could achieve that my ViewModel classes do have INotifyPropertyChanged support while not h

3条回答
  •  再見小時候
    2020-12-06 02:53

    There are a lot of ways to skin this cat.

    We have been toying with PostSharp to inject the INotifyProperty boilerplate. That seems to work pretty good.

    That being said, there's no reason why T4 wouldn't work.

    I agree with Dan that you should create the base class implementation of OnPropertyChanged.

    Have you considered just using a code snippet? It will write the boilerplate for you. The only disadvantage is that it will not update automatically if you want to change the property name at some later date.

    
    
      
        
    propin propin Code snippet for property and backing field with support for INotifyProperty Expansion
    type Property type int property Property name MyProperty

提交回复
热议问题