/// <summary> /// Finds the first field that matches the given fieldType. If not found, returns "Id". /// </summary> /// <param name="entityName">Name of the entity</param> /// <param name="fieldType">Type of the field</param> /// <returns></returns> public string GetFirstFieldName(string entityName, Type fieldType) { EntityDefinition entityDefinition = GetEntityDefinition(entityName); string strProp = entityDefinition.StringField; if (String.IsNullOrEmpty(strProp)) { PropertyInfo firstStrProp = ReflectionHelper.GetFirstProperty(GetTypeofEntity(entityName), fieldType); strProp = firstStrProp == null ? "Id" : firstStrProp.Name; } return(strProp); }
public EntityDefinition GetEntityDefinition(string entityName) { EntityDefinition definition = new EntityDefinition(); Type type = GetTypeofEntity(entityName); if (type == null) return null; EntityDefinitionAttribute attr = ReflectionHelper.GetAttribute<EntityDefinitionAttribute>(type); if (attr != null) { definition.Name = entityName; definition.IdMethod = attr.IdMethod; definition.StringField = attr.StringField; definition.OptimisticLockField = attr.OptimisticLockField; } else throw new Exception("Entity definition is missing: " + entityName); return definition; }
public List<FieldDefinitionAttribute> GetFilteringFields(string entityName) { EntityDefinition definition = new EntityDefinition(); Type type = GetTypeofEntity(entityName); if (type == null) return null; List<FieldDefinitionAttribute> list = new List<FieldDefinitionAttribute>(); PropertyInfo[] props = type.GetProperties(); foreach (PropertyInfo pi in props) { FieldDefinitionAttribute f = GenerateFieldDefinition(type, pi); if (f.IsFiltered) list.Add(f); } return list; }