什么信息?UserInfoProperty属性myMemberInfo[i].Name的类型是什么?

解决方案 »

  1.   

    you should show us the members and properties of UserInfoProperty
      

  2.   

    抛出的异常类型是什么?
    参照一下这个
    Type myType = ClassInstance.GetType();PropertyInfo myPropertyInfo = myType.GetProperty(PropertyName,BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public);myPropertyInfo.SetValue(ClassInstance,Value,null);
      

  3.   

    UserInfoProperty 里面有三个Property,UserName,Gender,Age,为了方便我都做成了string。我是想试验一下通过反射地对这三个Property进行。我明天去公司再看看。
      

  4.   

    are those properties public?PropertyInfo propertyInfo = myType.GetProperty(myMemberInfo[i].Name);
    if (propertyInfo != null)
    propertyInfo.SetValue(MyObject,"2",null);
    else
    Console.WriteLine("no such property");
      

  5.   

    ((System.Reflection.TargetInvocationException)(err))
    抛出来的是这个Exception。Property 是public的using System;namespace GetClassInstance
    {
    /// <summary>
    /// User Info Data Module
    /// </summary>
    public class UserInfoProperty
    {
    public UserInfoProperty()
    {
    } private string userName = null;
    private string gender = null;
    private string age; public string UserName
    {
    get
    {
    return userName;
    }
    set
    {
    this.UserName = value;
    }
    } public string Gender
    {
    get
    {
    return gender;
    }
    set
    {
     this.UserName = value;
    }
    } public string Age
    {
    get
    {
    return age;
    }
    set
    {
    this.age = value;
    }
    }
    }
    }
      

  6.   

    public class UserInfoProperty
    {
    public UserInfoProperty()
    {
    } private string userName = null;
    private string gender = null;
    private string age; public string UserName
    {
    get
    {
    return userName;
    }
    set
    {
                              //<---这里成循环了
    //this.UserName = value;
                                         this.userName = value;
    }
    } public string Gender
    {
    get
    {
    return gender;
    }
    set
    {
                                         //<---这里
     //this.UserName = value;
                                           this.gender = value;
    }
    } public string Age
    {
    get
    {
    return age;
    }
    set
    {
    this.age = value;
    }
    }
    }