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 static ExtendProperty Get(int key) { ExtendProperty property = null; lock (lockProvider) { propertys.TryGetValue(key, out property); } return(property); }
public static ExtendProperty RegisterProperty(string propertyName, Type propertyType, Type ownerType, object defaultValue, MetaData metaData) { var property = new ExtendProperty(propertyName, propertyType, ownerType); property.OverrideDefaultValue(ownerType, defaultValue); property.MetaData = metaData; ExtendPropertysProvider.Set(property.GetHashCode(), property); return(property); }
public static void Set(int key, ExtendProperty property) { if (propertys.Keys.Any(k => k == key)) { throw new NotSupportedException("不能为类型注册重复的属性!"); } lock (lockProvider) { propertys.TryAdd(key, property); } }
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); } }
public bool ClearValue(ExtendProperty property) { bool result = false; int propertyHash = property.GetHashCode(); int key = this.GetHashCode() ^ propertyHash; if (propertyValues.Keys.Any(k => k == key)) { object outObj = null; propertyValues.TryRemove(key, out outObj); result = true; } return(result); }
/// <summary> /// 添加验证信息规则 /// </summary> /// <param name="property">要验证的属性</param> /// <param name="func">验证规则方法</param> public void Add(ExtendProperty property, Func <string> func) { lock (this) { Func <string> fn = func; if (Rules.TryGetValue(property.PropertyName, out fn)) { Rules[property.PropertyName] = func; } else { Rules.Add(property.PropertyName, func); } } }
public object GetValue(ExtendProperty property) { int propertyHash = property.GetHashCode(); int key = this.GetHashCode() ^ propertyHash; object result = null; if (!propertyValues.TryGetValue(key, out result)) { result = property.GetDefaultValue(this.OwnerType); if (result == null) { result = property.DefaultValue; } } return(result); }
public virtual void SetValue(ExtendProperty property, object value) { var changingItemArgs = new ExtendPropertyValueChangingArgs() { Value = value, Item = GetOwner(), PropertyType = property.PropertyType, PropertyName = property.PropertyName, Cancel = false }; property.OnValueChanging(changingItemArgs); if (!changingItemArgs.Cancel) { var changedItemArgs = new ExtendPropertyValueChangedArgs(); int propertyHash = property.GetHashCode(); int key = this.GetHashCode() ^ propertyHash; if (propertyValues.Keys.Any(k => k == key)) { changedItemArgs.OldValue = propertyValues[key]; propertyValues[key] = value; } else { changedItemArgs.OldValue = null; propertyValues.TryAdd(key, value); } changedItemArgs.Item = GetOwner(); changedItemArgs.PropertyType = property.PropertyType; changedItemArgs.PropertyName = property.PropertyName; changedItemArgs.NewValue = value; changedItemArgs.PropertyInfo = property; property.OnValueChanged(changedItemArgs); OnPropertyChanged(property); //OnChildrenPropertyChanged(changedItemArgs); } }
public static ExtendProperty RegisterProperty(string propertyName, Type propertyType, Type ownerType,object defaultValue,MetaData metaData) { var property = new ExtendProperty(propertyName, propertyType, ownerType); property.OverrideDefaultValue(ownerType, defaultValue); property.MetaData = metaData; ExtendPropertysProvider.Set(property.GetHashCode(), property); return property; }
/// <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())); }
protected virtual void OnPropertyChanged(ExtendProperty property) { RaisePropertyChanged(property.PropertyName); }