【发布时间】:2018-05-19 21:28:54
【问题描述】:
是的,所以我设置了一个小 TestClass 来确定 GetMethod 将如何实际找到方法 Test(ref int i)。但到目前为止没有任何效果。
[Button(nameof(Method))]
public bool whatever;
private void Test(ref int i)
{
Debug.Log("Works");
}
private void Method()
{
Type[] types = { typeof(int) };
MethodInfo methodInfo = GetType().GetMethod(nameof(Test),
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static,
null, types, null);
Debug.Log(methodInfo);
}
我该怎么办?到目前为止,我在网上找不到任何东西(专门针对 GetMethod)
【问题讨论】:
-
嗯嗯嗯。是的,答案有帮助,但你真的认为我们问的是同一个问题吗?他的问题不是明确地与 ref/out 的 get 方法有关吗?所以只是为了清晰和简单,我希望它留下来。这当然不是我判断的:-)
-
构建表达式基本上对所有事情都使用反射。答案的前几句话也是你问题的答案。所以我认为这是一个合适的。
-
@thehennyy 最主要的是,问题不在于创建(当然)使用反射的表达式,只是反射。
-
@ChristophWolf 下面的一行答案包含了如何做到这一点的想法。
GetMethod()有一个接受参数参数数组的重载。
标签: c# reflection ref