Problem with CustomTyped casting and type checking

  • Thread starter Thread starter theinsanecoder
  • Start date Start date
T

theinsanecoder

I created several classes that supports custom typing as following:

Public Class DataManager(Of CustomType As {DataObject, New})

Public Class LockableDataManager(Of CustomType As {LockableDataObject,
New})
Inherits DataManager(Of CustomType)

Public NotInheritable Class BusinessManager
Inherits LockableDataManager(Of Business)

The problem i'm having is relative to CTYPE. If i try to verify that an
object passed to a function is of type LockableDataManager(Of
LockableDataObject) it never seems to resolve... If you follow the
hierarchy, a BusinessManager is a LockableDataManager(Of Business As
LockdableDataObject) and everything compiles fine but the following
line always returns false on the TYPEOF in the first part, the second
part works well.

If TypeOf pManager Is gumain.LockableDataManager(Of
gumain.LockableDataObject) AndAlso TypeOf Editor.EditedObject Is
gumain.LockableDataObject Then

(The Andalso Editor.EditedObject Is gumain.LockableDataObject resolves
to TRUE it is not the problem therefore)

Can you guys tell me what i can do to fix this and actually explain to
me what is wrong?

Thanks
 
I think i have found a part of my solution. It seems for a reason i
can't understand that CustomTyping a class is a valid way to work but
the CustomType is static, meaning it is that or nothing else. You
cannot use anything that is not of that type even if it derives from
it.

There fore to make my code work, i'd need to remove the CustomType from
the class definition which will obviously not happen since i'd need to
make major changes to most of my program.

To prove what i am saying here is a simply test: I changed my
declaration of the containing variable called pManager from the
previous code from :

Protected pManager As LockableDataManager(Of LockableDataObject)
To
Protected pManager As LockableDataManager(Of Business)

And now the calls resolve correctly. Since Business derives from
LockdableDataObject we can only assume one thing, CustomTyping doesn't
take into effect the inheritance of a class even when casting or when
checking the type using typeof...

Anyone has a simple anwser to help me?
 
Back
Top