private static string Name(PropertyInfo property) { object[] attrs = property.GetCustomAttributes(typeof(ColumnModelAttribute), true); if (attrs.Length > 0) { ColumnModelAttribute att = attrs[0] as ColumnModelAttribute; if (att != null) { return(att.ColumName); } } return(""); }
private static bool IsWriteable(PropertyInfo property) { object[] attributes = property.GetCustomAttributes(typeof(ColumnModelAttribute), false); if (attributes.Length == 1) { ColumnModelAttribute write = (ColumnModelAttribute)attributes[0]; if (write != null) { return(true); } } return(false); }
/// <summary> /// 请求转换为对象(有特性) /// </summary> /// <param name="Model">实例对象</param> /// <param name="prop">属性</param> private static void RequestToModelHasAttributes(object Model, PropertyInfo prop) { ColumnModelAttribute dma = null; foreach (Attribute attr in Attribute.GetCustomAttributes(prop)) { if (attr.GetType() == typeof(ColumnModelAttribute)) { dma = attr as ColumnModelAttribute; object value = HttpContext.Current.Request[dma.DBColumnName]; SetRequestValue(Model, value, prop); } } }
/// <summary> /// 数据列转换为对象(有特性) /// </summary> /// <param name="Model">实例对象</param> /// <param name="dr">数据行</param> /// <param name="prop">属性</param> private static void DataRowToModelHasAttributes(object Model, DataRow dr, PropertyInfo prop) { ColumnModelAttribute dma = null; foreach (Attribute attr in Attribute.GetCustomAttributes(prop)) { if (attr.GetType() == typeof(ColumnModelAttribute)) { dma = attr as ColumnModelAttribute; if (!(dr[dma.DBColumnName] is DBNull)) { prop.SetValue(Model, dr[dma.DBColumnName], null); } break; } } }