苯苯的博客

新随笔 联系 管理
  21 Posts :: 0 Stories :: 3 Comments :: 0 Trackbacks

2008年4月18日 #


同事小朱在非正常状态下写下的代码:

1.构造函数给类的Property创造实例。
正常版:
 public class Parameters
    
{
        
public Parameters()
        
{
            Server 
= new KeyValue();
        
        }

       
        
public KeyValue Server getset; }
     }
无奈版:
1 public Parameters()
2        {
3            foreach (PropertyInfo pi in this.GetType().GetProperties())
4            {
5                pi.SetValue(this, Activator.CreateInstance(pi.PropertyType), null);
6            }

7        }
posted @ 2008-04-18 09:42 one 阅读(24) | 评论 (0)编辑