create an entity from entityName string

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 24-Sep-2006 10:47:17   

Is there any helper function in LLBL that would create an entity object knowing the entity's name?

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 24-Sep-2006 14:24:10   

omar wrote:

Is there any helper function in LLBL that would create an entity object knowing the entity's name?

.net's Activator.CreateInstance perhaps.

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 25-Sep-2006 22:01:22   

If CreateInstance does not have good enough performances, it shouldn't be too hard coding or generating through a template an entity factory that relies on the EntityType enum to use the corresponding factory

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 25-Sep-2006 22:09:48   

There's a GeneralEntityFactory in the HelperFunctions/EntityFactories file...

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 25-Sep-2006 22:46:29   

mikeg22 wrote:

There's a GeneralEntityFactory in the HelperFunctions/EntityFactories file...

You can also get the value of an enum through the enum name. Using this in conjunction with the GeneralEntityFactory should get you what you want.


  string name = "OrderDetailsEntity";
  int entityTypeValue = 0;
  int[] values = (int[])System.Enum.GetValues(typeof(EntityType));

  for (int x = 0; x < values.Length; x++)
  {
    if (System.Enum.GetName(typeof(EntityType), x) == name)
    {
      entityTypeValue = x; 
    }
  }
  IEntity2 entity = GeneralEntityFactory.Create((EntityType)entityTypeValue);                       

HTH,

Phil