12

尽管存在 ParameterInfo.IsOut、ParameterInfo.IsIn(据我所见,它们都始终为假)、ParameterAttributes,但我很惊讶地发现“ref”和“out”参数没有被特殊属性标记。 In 和 ParameterAttributes.Out。相反,“ref”参数实际上由一种特殊的“Type”对象表示,而“out”参数只是带有附加属性的 ref 参数(我还不知道什么样的属性)。

无论如何,要创建一个 by-ref 参数,你调用 Type.MakeByRefType(),但我的问题是,如果你已经有一个 by-ref 类型,你如何回到原来的 Type?

提示:它不是 UnderlyingSystemType:

Type t = typeof(int);
Console.WriteLine(t.MakeByRefType().UnderlyingSystemType==t); // FALSE
4

1 回答 1

18

打电话GetElementType()

于 2010-06-13T20:04:41.333 回答