哪位高手知道这是怎么回事?怎么解决?急!!!
2008-02-25 09:39
295 查看
请位各位下面的问题怎么解决?
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;
}
异常捕捉结果:
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;
}
异常捕捉结果:
![](http://p.blog.csdn.net/images/p_blog_csdn_net/polic/未命名.bmp)
相关文章推荐
- 求助:MyEclipse 开发Html 页面时,输入< 就无响应~~~哪位高手能够告诉我为什么?改怎么解决~~
- 哪位知道基带怎么修复?
- [已解决]linux shell脚本生成的文件名末尾有问号是怎么回事
- 关于SQL语句的多表更新有哪位高手知道?
- Mac OS这是怎么了?哪位牛人知道的解释一下。
- 新建Android项目,会出现两个项目一个是自己创建的项目,另一个是“appcompat_v7”项目,这是怎么回事呢?该怎么解决呢?
- Win10预览版9860无法关闭自动升级怎么回事?如何解决?
- 学了php才知道MVC是怎么回事
- html是怎么回事?我是这样认为的,反正自己知道的不是很多!
- 记住一句话,阅读优秀的代码可以知道怎么写,做项目,可以解决问题!
- 打印机无法打印是怎么回事打印机故障维修技巧【已解决】
- 有哪位大神知道怎么获取系统自带浏览器加载完成的方法,并能够记录网页加载时间。
- 升级更新Win10后出现错误0x8024402f怎么回事?如何解决?
- 哪位大哥知道怎么用new动态分配一个指针数组?
- Google被和谐啦,哪位大侠知道怎么下载Android SDK?
- 不知道怎么解决这个异常,求高手赐教
- mysql中用存储过程怎么循环取变量值,哪位大侠知道,SOS!!!!
- 哪位大虾知道斜杠,反斜械, 破折号 等的英文怎么拼写
- 哪位高手帮我解决一个问题?
- (10.1.4.2)知道拟物化(skeuomorphism)是怎么回事吗?这个视频够直观