Esempio n. 1
0
 public DesignObjectPropertyDescriptor(PropertyDescriptorData descriptorData)
     : base(descriptorData.PropertyName, descriptorData.PropertyAttributes)
 {
     this.descriptorData = descriptorData;
     this.validationErrorPropertyName = (null != this.descriptorData.PropertyValidator ?
                                         string.Format(CultureInfo.InvariantCulture, "{0}{1}", this.descriptorData.PropertyName, DesignObjectWrapper.ValidationErrorSuffix) :
                                         null);
 }
Esempio n. 2
0
        public PropertyDescriptorCollection GetProperties()
        {
            Type type = this.GetType();

            if (!DesignObjectWrapper.TypePropertyCollection.ContainsKey(type))
            {
                MethodInfo initMethod = type.GetMethod("InitializeTypeProperties", BindingFlags.Static | BindingFlags.Public);
                PropertyDescriptorData[] properties = (PropertyDescriptorData[])initMethod.Invoke(null, null);
                List <DesignObjectPropertyDescriptor> descriptors = new List <DesignObjectPropertyDescriptor>(properties.Length);
                for (int i = 0; i < properties.Length; ++i)
                {
                    properties[i].OwnerType = type;
                    DesignObjectPropertyDescriptor descriptor = new DesignObjectPropertyDescriptor(properties[i]);
                    if (null != properties[i].PropertyValidator)
                    {
                        string localPropertyName    = properties[i].PropertyName;
                        PropertyDescriptorData data = new PropertyDescriptorData()
                        {
                            OwnerType          = type,
                            PropertyAttributes = new Attribute[] { BrowsableAttribute.No },
                            PropertyValidator  = null,
                            PropertySetter     = null,
                            PropertyType       = typeof(string),
                            PropertyName       = string.Format(CultureInfo.InvariantCulture, "{0}{1}", localPropertyName, ValidationErrorSuffix),
                            PropertyGetter     = (instance) => (!instance.IsPropertyValid(localPropertyName) ? instance.validationErrors[localPropertyName] : string.Empty),
                        };
                        descriptors.Add(new DesignObjectPropertyDescriptor(data));
                    }
                    descriptors.Add(descriptor);
                }
                for (int i = 0; i < DesignObjectWrapper.DefaultProperties.Length; ++i)
                {
                    descriptors.Add(this.ConstructDefaultPropertyPropertyDescriptor(DesignObjectWrapper.DefaultProperties[i]));
                }
                DesignObjectWrapper.TypePropertyCollection[type] = new PropertyDescriptorCollection(descriptors.ToArray(), true);
            }

            return(DesignObjectWrapper.TypePropertyCollection[type]);
        }
 public DesignObjectPropertyDescriptor(PropertyDescriptorData descriptorData)
     : base(descriptorData.PropertyName, descriptorData.PropertyAttributes)
 {
     this.descriptorData = descriptorData;
     this.validationErrorPropertyName = (null != this.descriptorData.PropertyValidator ?
         string.Format(CultureInfo.InvariantCulture, "{0}{1}", this.descriptorData.PropertyName, DesignObjectWrapper.ValidationErrorSuffix) :
         null);
 }
 DesignObjectPropertyDescriptor ConstructDefaultPropertyPropertyDescriptor(string propertyName)
 {
     DesignObjectPropertyDescriptor result = null;
     if (string.Equals(propertyName, HasErrorsProperty))
     {
         PropertyDescriptorData data = new PropertyDescriptorData()
         {
             OwnerType = this.GetType(),
             PropertyName = propertyName,
             PropertyAttributes = new Attribute[] { BrowsableAttribute.No },
             PropertySetter = null,
             PropertyType = typeof(bool),
             PropertyValidator = null,
             PropertyGetter = (instance) => (instance.HasErrors)
         };
         result = new DesignObjectPropertyDescriptor(data);
     }
     else if (string.Equals(propertyName, ContentProperty))
     {
         PropertyDescriptorData data = new PropertyDescriptorData()
         {
             OwnerType = this.GetType(),
             PropertyName = propertyName,
             PropertyAttributes = new Attribute[] { BrowsableAttribute.No },
             PropertySetter = (instance, value) => { instance.Content = (ModelItem)value; },
             PropertyType = typeof(ModelItem),
             PropertyValidator = null,
             PropertyGetter = (instance) => (instance.content)
         };
         result = new DesignObjectPropertyDescriptor(data);
     }
     else if (string.Equals(propertyName, AutomationIdProperty))
     {
         PropertyDescriptorData data = new PropertyDescriptorData()
         {
             OwnerType = this.GetType(),
             PropertyName = propertyName,
             PropertyAttributes = new Attribute[] { BrowsableAttribute.No },
             PropertySetter = null,
             PropertyType = typeof(string),
             PropertyValidator = null,
             PropertyGetter = (instance) => (instance.AutomationId)
         };
         result = new DesignObjectPropertyDescriptor(data);
     }
     else if (string.Equals(propertyName, TimestampProperty))
     {
         PropertyDescriptorData data = new PropertyDescriptorData()
         {
             OwnerType = this.GetType(),
             PropertyName = propertyName,
             PropertyType = typeof(DateTime),
             PropertyValidator = null,
             PropertyAttributes = new Attribute[] { BrowsableAttribute.No },
             PropertySetter = (instance, value) => { instance.UpdateTimestamp(); },
             PropertyGetter = (instance) => (instance.GetTimestamp())
         };
         result = new DesignObjectPropertyDescriptor(data);
     }
     return result;
 }
        public PropertyDescriptorCollection GetProperties()
        {
            Type type = this.GetType();
            if (!DesignObjectWrapper.TypePropertyCollection.ContainsKey(type))
            {
                MethodInfo initMethod = type.GetMethod("InitializeTypeProperties", BindingFlags.Static | BindingFlags.Public);
                PropertyDescriptorData[] properties = (PropertyDescriptorData[])initMethod.Invoke(null, null);
                List<DesignObjectPropertyDescriptor> descriptors = new List<DesignObjectPropertyDescriptor>(properties.Length);
                for (int i = 0; i < properties.Length; ++i)
                {
                    properties[i].OwnerType = type;
                    DesignObjectPropertyDescriptor descriptor = new DesignObjectPropertyDescriptor(properties[i]);
                    if (null != properties[i].PropertyValidator)
                    {
                        string localPropertyName = properties[i].PropertyName;
                        PropertyDescriptorData data = new PropertyDescriptorData()
                        {
                            OwnerType = type,
                            PropertyAttributes = new Attribute[] { BrowsableAttribute.No },
                            PropertyValidator = null,
                            PropertySetter = null,
                            PropertyType = typeof(string),
                            PropertyName = string.Format(CultureInfo.InvariantCulture, "{0}{1}", localPropertyName, ValidationErrorSuffix),
                            PropertyGetter = (instance) => (!instance.IsPropertyValid(localPropertyName) ? instance.validationErrors[localPropertyName] : string.Empty),
                        };
                        descriptors.Add(new DesignObjectPropertyDescriptor(data));
                    }
                    descriptors.Add(descriptor);
                }
                for (int i = 0; i < DesignObjectWrapper.DefaultProperties.Length; ++i)
                {
                    descriptors.Add(this.ConstructDefaultPropertyPropertyDescriptor(DesignObjectWrapper.DefaultProperties[i]));
                }
                DesignObjectWrapper.TypePropertyCollection[type] = new PropertyDescriptorCollection(descriptors.ToArray(), true);
            }

            return DesignObjectWrapper.TypePropertyCollection[type];
        }
Esempio n. 6
0
        DesignObjectPropertyDescriptor ConstructDefaultPropertyPropertyDescriptor(string propertyName)
        {
            DesignObjectPropertyDescriptor result = null;

            if (string.Equals(propertyName, HasErrorsProperty))
            {
                PropertyDescriptorData data = new PropertyDescriptorData()
                {
                    OwnerType          = this.GetType(),
                    PropertyName       = propertyName,
                    PropertyAttributes = new Attribute[] { BrowsableAttribute.No },
                    PropertySetter     = null,
                    PropertyType       = typeof(bool),
                    PropertyValidator  = null,
                    PropertyGetter     = (instance) => (instance.HasErrors)
                };
                result = new DesignObjectPropertyDescriptor(data);
            }
            else if (string.Equals(propertyName, ContentProperty))
            {
                PropertyDescriptorData data = new PropertyDescriptorData()
                {
                    OwnerType          = this.GetType(),
                    PropertyName       = propertyName,
                    PropertyAttributes = new Attribute[] { BrowsableAttribute.No },
                    PropertySetter     = (instance, value) => { instance.Content = (ModelItem)value; },
                    PropertyType       = typeof(ModelItem),
                    PropertyValidator  = null,
                    PropertyGetter     = (instance) => (instance.content)
                };
                result = new DesignObjectPropertyDescriptor(data);
            }
            else if (string.Equals(propertyName, AutomationIdProperty))
            {
                PropertyDescriptorData data = new PropertyDescriptorData()
                {
                    OwnerType          = this.GetType(),
                    PropertyName       = propertyName,
                    PropertyAttributes = new Attribute[] { BrowsableAttribute.No },
                    PropertySetter     = null,
                    PropertyType       = typeof(string),
                    PropertyValidator  = null,
                    PropertyGetter     = (instance) => (instance.AutomationId)
                };
                result = new DesignObjectPropertyDescriptor(data);
            }
            else if (string.Equals(propertyName, TimestampProperty))
            {
                PropertyDescriptorData data = new PropertyDescriptorData()
                {
                    OwnerType          = this.GetType(),
                    PropertyName       = propertyName,
                    PropertyType       = typeof(DateTime),
                    PropertyValidator  = null,
                    PropertyAttributes = new Attribute[] { BrowsableAttribute.No },
                    PropertySetter     = (instance, value) => { instance.UpdateTimestamp(); },
                    PropertyGetter     = (instance) => (instance.GetTimestamp())
                };
                result = new DesignObjectPropertyDescriptor(data);
            }
            return(result);
        }