索引器基类定义

 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     }
原文地址:https://www.cnblogs.com/ugvihc/p/11695010.html