System.Type to EntityType conversion

Posts   
 
    
idsn11
User
Posts: 39
Joined: 06-May-2008
# Posted on: 29-Apr-2011 15:39:58   

Hi! I have simple question:

it's possible to simply convert System.Type (IEntity2 implementor system type) to EntityType (IEntity2.LLBLGenProEntityTypeValue)?

I can do this by the expensive way:

var entityType = EntityFactoryFactory.GetFactory((Type)type).Create().LLBLGenProEntityTypeValue;

but it is so ... expensive )

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-May-2011 23:07:50   

I think this works:

Type type = new CustomerEntity().GetType();

EntityType eType;
Enum.TryParse(type.Name, out eType);

Assert.AreEqual(EntityType.CustomerEntity, eType);
David Elizondo | LLBLGen Support Team
idsn11
User
Posts: 39
Joined: 06-May-2008
# Posted on: 03-May-2011 06:14:17   
  1. I think "typeof(CustomerType).Name" more better
  2. And it is too implicitly.Are there any other way?
idsn11
User
Posts: 39
Joined: 06-May-2008
# Posted on: 03-May-2011 06:28:51   

Daelmo, thanks.

This version (code described below) is suitable for me.

(EntityType)Enum.Parse(typeof(EntityType), type.Name)

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-May-2011 08:13:54   

Yes, that's what I've tried to say but I just post approx code simple_smile Anyway good you are comfortable with your solution sunglasses

David Elizondo | LLBLGen Support Team