请位各位下面的问题怎么解决?
Form parentFrm = this.Owner;
getValue g = new getValue(MakeItem.GetValueControlProperty);
RuleEName = g(parentFrm,"TbEnglishName","Text").ToString();//调用,TbEnglishName是textbox的名称
public static object GetValueControlProperty(object ClassInstance,string ControlName,string PropertyName)
{
object Result=null;
Type myType = ClassInstance.GetType();
FieldInfo myFieldInfo = myType.GetField( ControlName,
BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.Public | BindingFlags.Instance);
//FieldInfo myFieldInfo = myType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
if(myFieldInfo != null)
{
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(myType);
PropertyDescriptor myProperty = properties.Find(PropertyName, false);
if(myProperty != null)
{
object ctr;
ctr = myFieldInfo.GetValue(ClassInstance);
try
{
Result = myProperty.GetValue(ctr);//这个地方出错,有异常发生,信息如下图.
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"Error");
}
}
}
return Result;
}
异常捕捉结果: