I have been having a go at coming up with some generic runtime code that will let me take certain actions based upon the presence of certain fields. I have been using entity.Fields["FieldName"] to access fields. This allows me to come up with code such as this:
public static void UpdateAutoFields(IEntity entity)
{
…
if(entity.Fields["LastModifiedBy"] != null)
{
entity.Fields["LastModifiedBy"].CurrentValue =System.Threading.Thread.CurrentPrincipal.Identity.Name;
}
…
}
One of the problems i am running into with this, is that if a field does not exist, the code entity.Fields["FieldName"] throws an ArgumentException (originating in SD.LLBLGen.Pro.ORMSupportClasses.EntityFields). I can get round this by putting all such code in try/catch blocks, but this is very inefficient.
Does a method exist to check if a field exists in an entity? If not, what would be the chance of adding one to the EntityFields class? Something like the following:
public bool ContainsField(string name)
{
return _entityFieldReferences.ContainsKey(name)
}