private static T GetObjectFromReaderRecord <T>(IDataReader reader) where T : new() { T item = new T(); foreach (PropertyInfo propertyInfo in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance)) { string ColumnName; DBColumnNameAttribute Attr = (DBColumnNameAttribute)propertyInfo.GetCustomAttribute(typeof(DBColumnNameAttribute)); if (Attr != null && Attr.ColumnName != string.Empty) { ColumnName = Attr.ColumnName; propertyInfo.SetValue(item, reader[Attr.ColumnName], null); } } return(item); }
public static Dictionary <string, string> GetTableNameAndColumns <T>(this IDbTable dbTable) { Type tType = typeof(T); Dictionary <string, string> columnNames; if (!CacheEntry.TypeCache.TryGetValue(tType, out columnNames)) { if (columnNames == null) { columnNames = new Dictionary <string, string>(); } PropertyInfo[] properties = tType.GetProperties(); var dbTableNameAttr = tType.GetCustomAttribute <DBTableNameAttribute>(); foreach (PropertyInfo property in properties) { object[] attributes = property.GetCustomAttributes(true); if (attributes.Length <= 0) { columnNames.Add(property.Name, property.Name); } foreach (object columnAttr in attributes) { DBColumnNameAttribute columnNameAttr = columnAttr as DBColumnNameAttribute; DBColumnIgnoreAttribute ignoreColumnAttr = columnAttr as DBColumnIgnoreAttribute; if (columnNameAttr != null) { if (ignoreColumnAttr == null || ignoreColumnAttr.Ignore == false) { columnNames.Add(property.Name, columnNameAttr != null ? columnNameAttr.Name : property.Name); } } } } if (columnNames != null && columnNames.Count >= 0) { CacheEntry.TypeCache.TryAdd(tType, columnNames); } } return(columnNames); }