예제 #1
0
        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));
        }
예제 #2
0
        public static ExtendProperty Get(int key)
        {
            ExtendProperty property = null;

            lock (lockProvider)
            {
                propertys.TryGetValue(key, out property);
            }
            return(property);
        }
예제 #3
0
        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);
        }
예제 #4
0
 public static void Set(int key, ExtendProperty property)
 {
     if (propertys.Keys.Any(k => k == key))
     {
         throw new NotSupportedException("不能为类型注册重复的属性!");
     }
     lock (lockProvider)
     {
         propertys.TryAdd(key, property);
     }
 }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
        }
예제 #7
0
 /// <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);
         }
     }
 }
예제 #8
0
        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);
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        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;
        }
예제 #11
0
 /// <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()));
 }
예제 #12
0
 protected virtual void OnPropertyChanged(ExtendProperty property)
 {
     RaisePropertyChanged(property.PropertyName);
 }