。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     }

 

相關文章
相關標籤/搜索