private static Dictionary <PropertyInfo, string> ExtractPropertyInfosAndDataHanderIdentifiers <TModelsBase>() where TModelsBase : ModelsBase { Dictionary <PropertyInfo, string> toReturn = null; Type entityType = typeof(TModelsBase); Type attributeType = typeof(DataHandlerAttribute); toReturn = entityType .GetProperties() .Select(x => { string identifier = null; DataHandlerAttribute dataHandlerAttribute = (DataHandlerAttribute)x.GetCustomAttribute(attributeType); if (dataHandlerAttribute != null) { identifier = dataHandlerAttribute.Identifier; } return(new { PropertyInfo = x, Identifier = identifier, }); }) .Where(x => !string.IsNullOrEmpty(x.Identifier)) .ToDictionary(x => x.PropertyInfo, x => x.Identifier); return(toReturn); }
private static string ExtractDataHandlerIdentifier <TModelsBase>() where TModelsBase : ModelsBase { string toReturn = null; Type entityType = typeof(TModelsBase); Type attributeType = typeof(DataHandlerAttribute); DataHandlerAttribute dataHandlerAttribute = (DataHandlerAttribute)Attribute.GetCustomAttribute( entityType, attributeType); if (dataHandlerAttribute == null) { throw new MissingDataHandlerAttributeException(entityType); } toReturn = dataHandlerAttribute.Identifier; return(toReturn); }