Modopt和.NET反射

5

我有一个CLI/C++接口,我想通过.NET反射来检查它。以下是源代码中的函数签名:

class ClassA;
template<typename _Type> class ClassTempA;

public interface class Test : BaseFunc {
public:
    ClassTempA<int>& SomeFunc2(ClassA inst) = 0;
};

以下是在.NET Reflector中查看该函数的样子:

unsafe ClassTempA<int>* modopt(IsImplicitlyDereferenced) SomeFunc2(ClassA inst);

有没有一种方法可以通过.NET反射获得modopt属性,还是必须使用元数据非托管API?
1个回答

7
您可以通过调用 ParameterInfo::GetOptionalCustomModifiers()ParameterInfo::GetRequiredCustomModifiers() 方法从 System.Reflection 中获取 modoptmodreq 信息。以下是一些示例,以说明如何使用这些方法来处理您的类型。请注意,保留 HTML 标签。
class ClassA;
template<typename _Type> class ClassTempA;

public interface class Test : BaseFunc {
public:
    ClassTempA<int>& SomeFunc2(ClassA inst) = 0;
};

array<Type^>^ GetModifiers()
{
    MethodInfo^ SomeFunc2 = Test::typeid->GetMethod("SomeFunc2");
    return method->ReturnParameter->GetOptionalCustomModifiers();
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接