PC Review


Reply
Thread Tools Rate Thread

Detect Type with Reflection?

 
 
xenophon
Guest
Posts: n/a
 
      22nd Aug 2005

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.


 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      22nd Aug 2005
>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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reflection and Type.GetType Andrew Ducker Microsoft C# .NET 16 29th Nov 2005 05:46 AM
Using reflection to get type members MarkB Microsoft Dot NET 2 2nd Jun 2005 11:14 AM
Reflection/Type Question =?Utf-8?B?RWRC?= Microsoft VB .NET 5 6th Feb 2005 03:37 PM
obtaining type using reflection =?Utf-8?B?SnVsaW8=?= Microsoft Dot NET Framework 2 12th Oct 2004 07:43 PM
using reflection to get array of type Gary Brewer Microsoft C# .NET 3 9th Sep 2004 02:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:40 AM.