使用反射获取函数的参数值

编程入门 行业动态 更新时间:2024-10-24 22:26:05
本文介绍了使用反射获取函数的参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的所有人,我在签名功能方面遇到了麻烦

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

更多推荐

使用反射获取函数的参数值

本文发布于:2023-11-11 18:37:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579250.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:反射   函数   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!