。net用lamda实现属性的优雅操作

 1  internal class ExtensionObjectURL
 2     {
 3         internal string name { get; set; }
 4     }
 5     internal static class Extension
 6     {
 7         internal static void NotifycationPropertyChanged<T, TProperty>(this T propertyChangedBase, Expression<Func<T, TProperty>> expression)
 8         {
 9             var body = expression.Body as MemberExpression;
10             if (body != null)
11             {
12                 var propertyName = body.Member.Name;
13                 // 做点神马呗
14                 return;
15             }
16             throw new InvalidOperationException("指定的expression无效,expression必须是对象的(属性,字段)成员的访问表达式。");
17         }
18 
19         internal void ss()
20         {
21             var s = new ExtensionObjectURL();
22             s.NotifycationPropertyChanged(p => p.);
23         }
24     }

原文地址:https://www.cnblogs.com/oceanho/p/5472974.html