/// <summary> /// 给定义的实体属性赋值 /// </summary> /// <param name="model"></param> /// <param name="relation"></param> public static void GetRelationInfo(object model, GetRelationName relation) { string _typeName; string _code; System.Reflection.PropertyInfo[] properties = model.GetType().GetProperties(); foreach (System.Reflection.PropertyInfo property in properties) { RelationNameAttribute[] columnAttributes = (RelationNameAttribute[])property.GetCustomAttributes(typeof(RelationNameAttribute), true); if (columnAttributes.Length > 0) { _typeName = columnAttributes[0].TypeName; _code = model.GetType().GetProperty(columnAttributes[0].PropertyName).GetValue(model, null).ToString(); object value = relation(_typeName, _code); property.SetValue(model, value, null); } } }
/// <summary> /// 给定义的实体属性赋值 /// </summary> /// <param name="model"></param> /// <param name="relation"></param> public static void GetRelationInfo(object model,GetRelationName relation) { string _typeName; string _code; System.Reflection.PropertyInfo[] properties = model.GetType().GetProperties(); foreach (System.Reflection.PropertyInfo property in properties) { RelationNameAttribute[] columnAttributes = (RelationNameAttribute[])property.GetCustomAttributes(typeof(RelationNameAttribute), true); if (columnAttributes.Length > 0) { _typeName = columnAttributes[0].TypeName; _code = model.GetType().GetProperty(columnAttributes[0].PropertyName).GetValue(model, null).ToString(); object value = relation(_typeName, _code); property.SetValue(model, value, null); } } }