protected static ExtendProperty RegisterProperty <TType>(Expression <Func <TType, object> > propertyNameExpression, ObjectRelations relaion = ObjectRelations.Normal) { PropertyInfo property = null; var member = propertyNameExpression.Body as MemberExpression; if (member == null) { var m = propertyNameExpression.Body as UnaryExpression; member = m.Operand as MemberExpression; } property = member.Member as PropertyInfo; if (relaion == ObjectRelations.Children) { childrenTypes.TryAdd(property.Name + "," + property.PropertyType.Name, property.PropertyType); } object defvalue = null; if (property.PropertyType.IsValueType) { defvalue = Activator.CreateInstance(property.PropertyType); } return(ExtendProperty.RegisterProperty(property.Name, property.PropertyType, typeof(TType), defvalue, null)); }
public void SetValue(string propertyName, object value) { var property = this.GetProperty(propertyName); if (property != null) { this.SetValue(property, value); } else { var newProperty = ExtendProperty.RegisterProperty(propertyName, typeof(object), OwnerType); this.SetValue(newProperty, value); } }
/// <summary> /// 注册扩展属性 /// </summary> /// <param name="obj"></param> /// <param name="propertyName"></param> /// <returns></returns> public static ExtendProperty RegisterProperty(this object obj, string propertyName) { return(ExtendProperty.RegisterProperty(propertyName, typeof(object), obj.GetType())); }