Detect Type with Reflection?

  • Thread starter Thread starter xenophon
  • Start date Start date
X

xenophon

I have an instanced class that needs to, at Runtime using Reflection,
check the current AppDomain for the existence of another Type, and if
it exists create a new instance. If that Type is not in the AppDomain,
then attempt to load it from disk.

How can I do that (C#)?

Thanks.
 
I have an instanced class that needs to, at Runtime using Reflection,
check the current AppDomain for the existence of another Type

You can iterate through the assemblies returned by
AppDomain.GetAssemblies and check for the one where teh type is
implemented.
and if it exists create a new instance.

When you find the right Assembly instance just call CreateInstance on
it and pass in the type name.

If that Type is not in the AppDomain,
then attempt to load it from disk.

With Assembly.Load/LoadFrom. You can always do this if you want (skip
checking if it's already loaded) since the assembly will only loaded
once anyway.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top