using a Code Snippet for INotifyPropertyChanged

前端 未结 5 593
再見小時候
再見小時候 2020-12-17 23:46

I found this code snippet for INotifyPropertyChanged

But it shows the code like this :

\"INotifyProperty

5条回答
  •  旧巷少年郎
    2020-12-18 00:29

    It's surprising to me that the following suggestion hasn't been made. I took your initial snippet (from the originating author's page) and made the following modifications. You should be able to copy-and-paste this into your own snippet file.

    
    
        
            
    propn propn Code snippet for property and backing field in class implementing INotifyPropertyChanged Brian Schroer, Modified by RLH Expansion
    type Property Type int variable Underlying Variable _myProperty property Property name MyProperty notifyMethod name of method to raise PropertyChanged event NotifyPropertyChanged

    What's Changed

    First, I added a new literal variable. This creates a new, updatable item that you can tab from within the snippet. The variable name is defaulted to _propertyName which, as you can see, is a lowercase name. Note, unlike the original snippet, the underscore was being hardcoded before the PropertyName literal. In my code, I've split out the variable name from the property name.

    I chose not to hardcode the underscore in my snippet so that if others use this code, they are at liberty to choose a different style of variable name. However, by way of the default, I am hinting at using the underscore.

    If you want to force the underscore, then change the default variable value to propertyName. Then, everywhere variable is referenced, place the _ character before the reference.

提交回复
热议问题