Comparing types.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Blanco

    #1

    Comparing types.

    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(DynamicL oader.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


  • Chris Blanco

    #2
    Re: Comparing types.

    That gives me the same problem. Here is the new "if" statement:

    if(!t.IsSubclas sOf(typeof(Dyna micLoader.Comma nd)))
    {
    return;
    }

    Once again the if statement is ALWAYS true. It should evaluate to false if
    indeed the two classes are the same.
    "Val Savvateev" <vsavvateev@mer idium.com_NO_SP AM> wrote in message
    news:ucmib01WDH A.2040@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Use Type.IsSubclass Of instead.
    >
    > "Chris Blanco" <cblancoNOSPAM@ necam.com> wrote in message
    > news:eajrjs1WDH A.1004@TK2MSFTN GP12.phx.gbl...[color=green]
    > > 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[/color]
    > examine[color=green]
    > > the directory to see if there is a class that is derived from a certain[/color]
    > base[color=green]
    > > 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[/color]
    > that[color=green]
    > > is currently being examined is of a certain base type. The problem is[/color][/color]
    that[color=blue][color=green]
    > > 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(DynamicL oader.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
    > >
    > >[/color]
    >
    >[/color]


    Comment

    • Jon Skeet

      #3
      Re: Comparing types.

      Chris Blanco <cblancoNOSPAM@ necam.com> wrote:[color=blue]
      > 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(DynamicL oader.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"[/color]

      My guess is that you'll find you've either got the same assembly loaded
      twice, or the type DynamicLoader.C ommand is in two different
      assemblies. Check whether or not t.BaseType.Asse mbly==
      typeof(DynamicL oader.Command). Assembly. Check where they're being
      loaded from, etc.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Chris Blanco

        #4
        Re: Comparing types.

        That was exactly it. Thanks John!!!!


        "Jon Skeet" <skeet@pobox.co m> wrote in message
        news:MPG.1999d3 54a70c20bf98a27 8@news.microsof t.com...[color=blue]
        > Chris Blanco <cblancoNOSPAM@ necam.com> wrote:[color=green]
        > > 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[/color][/color]
        examine[color=blue][color=green]
        > > the directory to see if there is a class that is derived from a certain[/color][/color]
        base[color=blue][color=green]
        > > 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[/color][/color]
        that[color=blue][color=green]
        > > is currently being examined is of a certain base type. The problem is[/color][/color]
        that[color=blue][color=green]
        > > 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(DynamicL oader.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"[/color]
        >
        > My guess is that you'll find you've either got the same assembly loaded
        > twice, or the type DynamicLoader.C ommand is in two different
        > assemblies. Check whether or not t.BaseType.Asse mbly==
        > typeof(DynamicL oader.Command). Assembly. Check where they're being
        > loaded from, etc.
        >
        > --
        > Jon Skeet - <skeet@pobox.co m>
        > http://www.pobox.com/~skeet/
        > If replying to the group, please do not mail me too[/color]


        Comment

        Working...