[英]How do I know that a parameter uses ref or params modifier?
尽管ParameterDefinition
不包含IsRef
或IsParams
,但很容易从其他两个属性中确定这两个属性。
当参数包含ref
修饰符时, ParameterDefinition.ParameterType.IsByReference
值为true
。 否则,即使实际参数是引用类型,它也为false
。
至于params
, CustomAttributes
集合包含一个与System.ParamArrayAttribute
相对应的元素。
以下代码说明了如何确定四种状态:
using System;
using System.Linq;
using Mono.Cecil;
...
if (definition.IsOut)
{
// There is an `out` modifier.
}
else if (definition.ParameterType.IsByReference)
{
// There is a `ref` modifier.
}
else if (definition.CustomAttributes.Any(attribute =>
attribute.AttributeType.FullName == typeof(ParamArrayAttribute).FullName))
{
// There is a `params` modifier.
}
else
{
// There are no modifiers.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.