런타임시로드 된 C++ 어셈블리에서 버전 정보를 최상위 응용 프로그램에 등록 할 수 있어야합니다.런타임시 .NET 어셈블리 초기화
array<System::Reflection::Assembly^>^ assemblies = System::AppDomain::CurrentDomain->GetAssemblies();
for each(System::Reflection::Assembly^ assembly in assemblies)
{}
을 그러나 당신은 어떻게 내 조립하고 시스템 어셈블리있는 결정할 수 있습니다 : 내가 좋아하는 뭔가 생각했다. 이 코드가 호출 할 수있는 클래스에 정적 메서드를 추가하는 방법이 있습니까?
실제로 사용하고있는 코드는 다음과 같습니다. Foo 클래스의 특성을 가져 와서 정적 메서드를 호출하여 자체 등록을 요청할 수있었습니다.
public ref class Foo
{
public:
Foo()
{
};
private:
};
public ref class InitOnLoad : System::Attribute
{
public:
InitOnLoad()
{
Foo ^foo = gcnew Foo();
System::Type^ thisType = foo->GetType();
// get a list of types which are marked with the InitOnLoad attribute
array<System::Reflection::Assembly^>^ assemblies = System::AppDomain::CurrentDomain->GetAssemblies();
for each(System::Reflection::Assembly^ assembly in assemblies)
{
try
{
System::Type^ type = System::Type::GetType("UtilsDotNet.Foo");
array<Object^>^ attributes = assembly->GetCustomAttributes(type, false);
if(attributes->Length > 0)
{
auto field =
type->GetFields(
System::Reflection::BindingFlags::Static |
System::Reflection::BindingFlags::Public |
System::Reflection::BindingFlags::NonPublic);
}
}
catch (...)
{
}
}
}
};
답장을 보내 주셔서 감사합니다. 내가 언급 한 것과 비슷한 것을하려고 시도했지만 어떤 이유로 GetCustomAttributes를 호출 할 때 속성이 0입니다. – user1145533
속성 코드와 속성을 찾는 코드를 게시하면 도움을 드리겠습니다. –
방금 시도한 코드로 질문을 업데이트했습니다.로드 할 때 GetCustomAttributes를 반환 할 수 없습니다. 형식을 가져올 때 __typeof를 시도했지만 그 중 하나도 작동하지 않았습니다. – user1145533