标题可能描述的不清楚,事情是这样的:
我有一个类  Task tk=new Task();
有一些属性,比如  tk.id.tk.name.然后有一个字符串string s="tk.id";我怎样才能将S变成tk的属性来进行操作呢

解决方案 »

  1.   

    string s="tk.id";
    换一种存储方式,比如Dictionary集合,把tk保存为一个Ojbect对象,或者它的父类名称,id就作为一个字符串保存
    比如:Dictionary<string,Object>  dict ...   dict.add("class",tk); dict.add("property","id");
    然后解析:Type type = dict["class"].GetType();
                    PropertyInfo property = type.GetProperty(dict["property"]);
                    string s = property.GetValue(cmdAsk, null).ToString();
      

  2.   

    string s = property.GetValue(dict["class"], null).ToString();
    这里写错了。更正