索引器基类定义

 1   public  class ClassIndex
 2     {
 3        
 4         public object this[string index]
 5         {
 6             get
 7             {
 8                 object result = null;
 9                 foreach (var item in this.GetType().GetProperties())
10                 {
11                     if (index == item.Name)
12                     {
13                         result = item.GetValue(item);
14                     }
15 
16                 }
17                 return result;
18             }
19             set
20             {
21                 foreach (var item in this.GetType().GetProperties())
22                 {
23                     if (index == item.Name)
24                     {
25                         item.SetValue(this, value,null);
26                         
27                     }
28                 }
29 
30             }
31 
32         }
33     }

 

posted @ 2019-10-17 20:55  苍云者  阅读(97)  评论(0编辑  收藏  举报