Comparing types.

  • Thread starter Thread starter Chris Blanco
  • Start date Start date
C

Chris Blanco

I am building a Dynamic assembly loader which will scan and monitor a
directory, when a new assembly gets placed in that directory it will examine
the directory to see if there is a class that is derived from a certain base
class, if so it will create a n instance of that class and add it to a
command map. The problem I am having is determining if the System.Type that
is currently being examined is of a certain base type. The problem is that
the types are NEVER equal, even when they are the same types. Here is a
clip of what I am trying to do:

<code>
public void AddAllFromType(Type t)
{
object instance=null;
//check to see if type is command
if(t.BaseType != typeof(DynamicLoader.Command) )
{
//we aren't the right type so we don't care.
return;
}
...
</code>

The if statement above is ALWAYS true even if t.Basetype evaluates to
"DynamicLoader.Command"

Please Help!!!!

Chris Blanco
NEC AMERICA
Software Engineer
 
That gives me the same problem. Here is the new "if" statement:

if(!t.IsSubclassOf(typeof(DynamicLoader.Command)))
{
return;
}

Once again the if statement is ALWAYS true. It should evaluate to false if
indeed the two classes are the same.
 
Chris Blanco said:
I am building a Dynamic assembly loader which will scan and monitor a
directory, when a new assembly gets placed in that directory it will examine
the directory to see if there is a class that is derived from a certain base
class, if so it will create a n instance of that class and add it to a
command map. The problem I am having is determining if the System.Type that
is currently being examined is of a certain base type. The problem is that
the types are NEVER equal, even when they are the same types. Here is a
clip of what I am trying to do:

<code>
public void AddAllFromType(Type t)
{
object instance=null;
//check to see if type is command
if(t.BaseType != typeof(DynamicLoader.Command) )
{
//we aren't the right type so we don't care.
return;
}
...
</code>

The if statement above is ALWAYS true even if t.Basetype evaluates to
"DynamicLoader.Command"

My guess is that you'll find you've either got the same assembly loaded
twice, or the type DynamicLoader.Command is in two different
assemblies. Check whether or not t.BaseType.Assembly==
typeof(DynamicLoader.Command).Assembly. Check where they're being
loaded from, etc.
 
That was exactly it. Thanks John!!!!


Jon Skeet said:
My guess is that you'll find you've either got the same assembly loaded
twice, or the type DynamicLoader.Command is in two different
assemblies. Check whether or not t.BaseType.Assembly==
typeof(DynamicLoader.Command).Assembly. Check where they're being
loaded from, etc.
 
Back
Top