type checking with libraries

  • Thread starter Thread starter Alessandro Fragnani de Morais
  • Start date Start date
A

Alessandro Fragnani de Morais

Hi,

In Win32 framework, we used to work with .dll files as libraries of
functions, not objects. We couldn't use objects because using a "IS"
operation (on Delphi for instance) to check the type of the class, should
not work.. I mean:

1. I have an object (TForm) on my application (.exe)
2. I have another object (TForm also) that is created on a library (.dll)
3. If in some moment I need to check the compatibility between this two
objects (formFromEXE IS formFromDLL), this always returns FALSE..

In .NET framework it appears to work.. (at least it was what I understood
while reading the documentation).

Is it true?

Thanks

Alessandro
 
Alessandro Fragnani de Morais said:
In Win32 framework, we used to work with .dll files as libraries of
functions, not objects. We couldn't use objects because using a "IS"
operation (on Delphi for instance) to check the type of the class, should
not work.. I mean:

1. I have an object (TForm) on my application (.exe)
2. I have another object (TForm also) that is created on a library (.dll)
3. If in some moment I need to check the compatibility between this two
objects (formFromEXE IS formFromDLL), this always returns FALSE..

In .NET framework it appears to work.. (at least it was what I understood
while reading the documentation).

Is it true?

No - if two types which happen to have the same name (and may be
exactly the same in all other ways too) are loaded from different
assemblies, they are regarded as different types. I don't know whether
it'll be entirely relevant to you or not, but the following page may
help:

http://www.pobox.com/~skeet/csharp/plugin.html
 
Jon Skeet said:
No - if two types which happen to have the same name (and may be
exactly the same in all other ways too) are loaded from different
assemblies, they are regarded as different types. I don't know whether
it'll be entirely relevant to you or not, but the following page may
help:

http://www.pobox.com/~skeet/csharp/plugin.html

Jon,

That is the point.. They ARE from the same assembly.

For instance..

1. I will create a plug-in for my APP that creates some forms
(System.Windows.Forms.Form class).
2. At some point of my main application that loads this plug-in, I need to
check for objects to broadcast some methods. So, I need to check the class
type (Ok, I should work with Interfaces at this point)

In Win32 framework, this cast will always returns FALSE.. but, what you're
saying is that if they are from the same assembly, the cast should work?

If is true, God bless .NET :-)

Thanks

Alessandro
 
Alessandro Fragnani de Morais said:
That is the point.. They ARE from the same assembly.

For instance..

1. I will create a plug-in for my APP that creates some forms
(System.Windows.Forms.Form class).
2. At some point of my main application that loads this plug-in, I need to
check for objects to broadcast some methods. So, I need to check the class
type (Ok, I should work with Interfaces at this point)

In Win32 framework, this cast will always returns FALSE.. but, what you're
saying is that if they are from the same assembly, the cast should work?

If is true, God bless .NET :-)

If they're from the same assembly, it should indeed work. If you have
any problems with it, look at the page again and if that still doesn't
help, come up with a short but complete example which demonstrates the
problem. Hopefully it'll all just work for you though :)
 
Back
Top