本文介绍了使用反射获取函数的参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,我在签名功能方面遇到了麻烦
void event ( ref string BusinessObjectInfo, out bool BubbleEvent) {我想用使用反射在函数内部的BubbleEvent值。你能建议我该怎么做。 我试过以下 var v = MethodBase.GetCurrentMethod()。GetParameters()。GetValue(1) 但仍有问题,不知道从哪里获得价值。 感谢您的帮助
解决方案正如彼得所说,它没有多大意义:为什么要通过反射从函数内部访问参数? 特别是当它是一个 out 参数时,因为它没有你在实际方法中给出的值以外的值... 我不能想到也许你试图以完全错误的方式做某事,并且应该退后一步再思考。
该参数定义为 out ,这意味着它不需要通过调用方法初始化 - 您应该在函数内为其赋值。 如果你想传入一个值,更改它并将其传回去使用 ref 而不是出
Dear All, I am having trouble in a function of signature
void event(ref string BusinessObjectInfo, out bool BubbleEvent) {I want to use value of BubbleEvent inside the function using reflection. Can you suggest How should I go for it. I have tried following var v = MethodBase.GetCurrentMethod().GetParameters().GetValue(1) but still in trouble don't know where to get the value. Thank you for help
解决方案 As Peter says, it doesn't make a lot of sense: "Why should one access a parameter from inside the function by reflection?" Particularly when it is an out parameter, as it has no value other than that which you give it in the actual method... I can't hep thinking that perhaps you are trying to do something in entirely the wrong way, and should possibly take a step back and think again.The parameter is defined as out which means it does not need to be initialised by the calling method - you are supposed to assign it a value within your function. If you want to pass a value in, change it and pass it back out use ref instead of out更多推荐
使用反射获取函数的参数值
发布评论