Is there a good strongly typed way to do PropertyChanged events in C#?

前端 未结 7 1092
轮回少年
轮回少年 2020-12-05 12:19

It must be a somewhat common event to change the name of a property and expect the Rename functionality in Visual Studio to take care of all the necessary renaming, except f

7条回答
  •  粉色の甜心
    2020-12-05 12:37

    You should check out this blog post. It gives you the ability to do this:

    string propertyName = TypeHelper.GetPropertyName(u => u.LastProjectCode);
    
    PropertyInfo property1 = TypeHelper.GetProperty((SomeClass o) => o.InstanceProperty.Length);
    
    PropertyInfo property2 = TypeHelper.GetProperty(() => SomeClass.StaticProperty.Length);
    

    Renames in Visual Studio/Resharper/Refactor Pro should work for you then.

提交回复
热议问题