modopt and .NET reflection

拜拜、爱过 提交于 2019-12-22 07:28:08

问题


I have a CLI/C++ interface that I want to examine via .NET Reflection. Here's the function signature in the source code:

class ClassA;
template<typename _Type> class ClassTempA;

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

Here's what the function looks like when examined in .NET Reflector:

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

Is there a way to get at the modopt attributes via .NET reflection, or do I have to use the Metadata Unmanaged API?


回答1:


You can get the modopt and modreq info from System.Reflection by calling ParameterInfo::GetOptionalCustomModifiers() and ParameterInfo::GetRequiredCustomModifiers(), respectively. To illustrate with your types, see the following.

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();
}


来源:https://stackoverflow.com/questions/408028/modopt-and-net-reflection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!