Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET assembly initialisation at runtime
    primarykey
    data
    text
    <p>At runtime I need to be able to get my loaded C++ assemblies to register their version information with a top level application. I was thinking of something like:</p> <pre><code> array&lt;System::Reflection::Assembly^&gt;^ assemblies = System::AppDomain::CurrentDomain-&gt;GetAssemblies(); for each(System::Reflection::Assembly^ assembly in assemblies) {} </code></pre> <p>But how can you determine which are my assemblies and which are system assemblies. Is there some way of adding some static method to my classes that this code can call?</p> <p>Here is the code I was actually using, I was trying to get the attributes of the Foo class so that I could then call a static method to request it to register itself.</p> <pre><code>public ref class Foo { public: Foo() { }; private: }; public ref class InitOnLoad : System::Attribute { public: InitOnLoad() { Foo ^foo = gcnew Foo(); System::Type^ thisType = foo-&gt;GetType(); // get a list of types which are marked with the InitOnLoad attribute array&lt;System::Reflection::Assembly^&gt;^ assemblies = System::AppDomain::CurrentDomain-&gt;GetAssemblies(); for each(System::Reflection::Assembly^ assembly in assemblies) { try { System::Type^ type = System::Type::GetType("UtilsDotNet.Foo"); array&lt;Object^&gt;^ attributes = assembly-&gt;GetCustomAttributes(type, false); if(attributes-&gt;Length &gt; 0) { auto field = type-&gt;GetFields( System::Reflection::BindingFlags::Static | System::Reflection::BindingFlags::Public | System::Reflection::BindingFlags::NonPublic); } } catch (...) { } } } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload