反映出GetValue. [英] GetValue in reflection.

查看:121
本文介绍了反映出GetValue.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何检测_Object是否具有用于反射的空值?

代码:

Hello All,

How can I detect if the _Object has null value used in reflection?

code:

orgfldInfo[i].GetValue(_Object, null)



当我使用上面的代码时,它给我错误:
来自目标调用的错误"


堆栈跟踪异常




When I am using above code it gives me error:
"Error from target invocation"


Stack trace exception


at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at InSync.BillingBL.CPayments.BillingLog(Object _OldValue, Object _NewValue, String PageName, String Event) in D:\InSync5.4\CareEMRBillingBL\CPayments.cs:line 168

推荐答案

我敢打赌错误消息不是您所说的来自目标调用的错误".可能更像是调用的目标抛出了异常".任何人,除所有异常信息(包括stacktrace)外,还请提供完整的错误消息.

使用调试器,您应该在该行上放置一个断点,并检查所有变量中是否有异常值.

修改:
或您的意思是这样的:

I''d place a bet that the error message is not "Error from target invocation" as you stated. It''s probably more along the lines of "Exception has been thrown by the target of an invocation.". Anywho, please give the complete error message in addition to all exception information (including the stacktrace).

Using the debugger you should place a breakpoint on that line and check all variables for unusual values.

Modification:
or did you mean something like this:

if(_Object!=null)
{
    orgfldInfo[i].GetValue(_Object, null)
}
else
{
    //Do something else
}



最终修改


干杯

曼弗雷德(Manfred)



End Modification


Cheers

Manfred


这篇关于反映出GetValue.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆