Best way to reference field names in code

Posts   
 
    
Posts: 1268
Joined: 10-Mar-2006
# Posted on: 17-Mar-2006 02:58:28   

When referencing a field name in code like:

dropDownLookup.DisplayField="MyField";

What is the prefered method:

1) dropDownLookup.DisplayField=MyEntityFieldIndex.MyField.ToString();

or

2) dropDownLookup.DisplayField=MyEntityFields.MyField.Name;

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Mar-2006 08:34:13   

Both can work, but I'd prefer the second one:

2) dropDownLookup.DisplayField=MyEntityFields.MyField.Name;

It's more object oriented, since MyEntityFieldIndex is an enum, and I don't feel like getting my such info based on an Enum Item string Name.

Posts: 1268
Joined: 10-Mar-2006
# Posted on: 17-Mar-2006 17:02:45   

Well, that was what I was doing at first. However, using option 2 causes EntityFieldFactory to create a new object. That uses a case statement to determine which object to create, then calls 'new EntityField()'

So, I was thinking the enum would be way faster use less memory, etc. (The compiler might even do the substituion at compile time, would have to check the IL to see if it is smart enough for that)