Determining if an object is LLBLGen EntityCollection(generics)

Posts   
 
    
Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 21-Aug-2006 12:12:45   

Somewhere in the code of my Gui I get the typedescriptor of an object. This Type can describe some fo the .Net type (string, int32....) or an LLBLGen Pro EntityCollection (I'm using Adapter, with generics collection)

Said that I have the following code:


Dim T as Type

T=BindingSource.GetItemProperties(nothing).item(44).PropertyType   '44 is EntityCollection2(Of MyAddressEntity)

How can i check if T represent an LLBLGen Pro EntityCollection? The type of entity in the collection is not relevant. I only need to know if it is an LLBLGen EntityCollection.

I know that My entity collectionc inherits from EntityCollectionBase2(Of TEntity); both EntityCollectionBase2 and EntityCollectionBase inherit from CollectionCore(Of TEntity); also EntityCollectionNonGeneric inherit from EntityCollectionBase2(Of EntityBase2).

I'tried following code, without success; they all return False: disappointed

T is gettype(sd.LLBLGen.Pro.ORMSupportClasses.CollectionCore(Of))
T is gettype(sd.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2(Of))

T.GetGenericTypeDefinition is gettype(sd.LLBLGen.Pro.ORMSupportClasses.CollectionCore(Of))
T.GetGenericTypeDefinition is gettype(sd.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2(Of))

T.IsSubclassOf(gettype(sd.LLBLGen.Pro.ORMSupportClasses.CollectionCore(Of)))
T.IsSubclassOf(gettype(sd.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2(Of)))

T.GetGenericTypeDefinition .IsSubclassOf(gettype(sd.LLBLGen.Pro.ORMSupportClasses.CollectionCore(Of)))
T.GetGenericTypeDefinition .IsSubclassOf(gettype(sd.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase2(Of)))

How can I do? There must exist a simpe method to check the type (or the basetype) of a generic collection. I don't wanna resor to some like T.BaseType.FullName Like "SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase*"

Thanks, Max

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 21-Aug-2006 19:27:16   

Hi,

checking for IEntityCollection implementation should make it simple_smile

Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 22-Aug-2006 10:28:27   

Thanks, the following code do the job simple_smile

Dim InterfaceName as String

InterfaceName = GetType(SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2).FullName

If  PropCollection(44).PropertyType.GetInterface(InterfaceName) IsNot Nothing Then
     ....
     ....
     ....
Endif

Max

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 22-Aug-2006 10:54:34   

Or something like this: if typeof(suspectedentity) is SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2 then ... end if

Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 22-Aug-2006 14:40:06   

mihies wrote:

Or something like this: if typeof(suspectedentity) is SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2 then ... end if

I believe that I can't do that, because I don't have any instance of the object (the collection). I have a propertieDescriptor that give me an instance of System.Type that represent the entityCollection. From my understanding, TypeOf ... Is .... work with object instance, not with object type described by an instance of System.Type.

Thanks, Max

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 22-Aug-2006 20:16:20   

Right TypeOf .. Is works only with instances. Missed the fact that you don't have an instance..