Inheritance: MemberDescriptor
Exemple #1
0
 void IBindingList <T> .ApplySort(
     SCM.PropertyDescriptor property,
     SCM.ListSortDirection direction
     )
 {
     AsBindingList.ApplySort(property, direction);
 }
        protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)
        {
            switch (propertyDescriptor.Name)
            {
                case "AllowedModes":
                    var valueName = string.Concat(bindingContext.ModelName, ".", propertyDescriptor.Name);
                    var valueObject = bindingContext.ValueProvider.GetValue(valueName);

                    if (valueObject != null)
                    {
                        // One or more selected - default behaviour is fine
                        base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
                    }
                    else
                    {
                        // None selected, blank it out
                        SetProperty(controllerContext, bindingContext, propertyDescriptor, new List<UrlPickerMode>());
                    }

                    break;
                default:
                    base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
                    break;
            }
        }
 public LoginViewDesignerRegion(ControlDesigner owner, object obj, ITemplate template, System.ComponentModel.PropertyDescriptor descriptor, TemplateDefinition definition) : base(definition)
 {
     this._template  = template;
     this._object    = obj;
     this._prop      = descriptor;
     base.EnsureSize = true;
 }
Exemple #4
0
 public SortExpression(string propertyName, ListSortDirection sortDirection)
 {
     this.PropertyName       = propertyName;
     this.SortDirection      = sortDirection;
     this.PropertyDescriptor = null;
     this.a = new Hashtable();
 }
Exemple #5
0
        private void SetPackageAsDirty(IDTSSequence container, string expression, object objectChanged)
        {
            try
            {
                if (!string.IsNullOrEmpty(expression))
                {
                    shouldSkipExpressionHighlighting = true; //this flag is used by the expression highlighter to skip re-highlighting if all that's changed is the string of an existing expression... if one has been removed, then re-highlight
                }

                PropertyDescriptorCollection             properties          = TypeDescriptor.GetProperties(objectChanged);
                System.ComponentModel.PropertyDescriptor expressionsProperty = properties.Find("Expressions", false);

                // Mark package object as dirty
                IComponentChangeService changeService = (IComponentChangeService)designer.GetService(typeof(IComponentChangeService));
                if (objectChanged == null)
                {
                    changeService.OnComponentChanging(container, null);
                    changeService.OnComponentChanged(container, null, null, null); //marks the package designer as dirty
                }
                else
                {
                    changeService.OnComponentChanging(objectChanged, expressionsProperty);
                    changeService.OnComponentChanged(objectChanged, expressionsProperty, null, null); //marks the package designer as dirty
                }
                if (container is Package)
                {
                    SSISHelpers.MarkPackageDirty((Package)container);
                }
            }
            finally
            {
                shouldSkipExpressionHighlighting = false;
            }
        }
Exemple #6
0
 public SortExpression(string propertyName)
 {
     this.PropertyName       = propertyName;
     this.SortDirection      = ListSortDirection.Ascending;
     this.PropertyDescriptor = null;
     this.a = new Hashtable();
 }
Exemple #7
0
            internal bool IsSelectable()
            {
                Object runtimeComp = this.RuntimeComponent;

                Debug.Assert(runtimeComp != null);

                // the selected datasource must not be private
                MemberAttributes   modifiers     = 0;
                PropertyDescriptor modifiersProp = TypeDescriptor.GetProperties(runtimeComp)["Modifiers"];

                if (modifiersProp != null)
                {
                    modifiers = (MemberAttributes)modifiersProp.GetValue(runtimeComp);
                }

                if (modifiers == MemberAttributes.Private)
                {
                    String message = String.Format(SR.GetString(SR.ListGeneralPage_PrivateMemberMessage), dataSourceName);
                    String caption = SR.GetString(SR.ListGeneralPage_PrivateMemberCaption);

                    MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                // ok to select
                return(true);
            }
Exemple #8
0
        /// <summary>
        /// </summary>
        private void LoadDataSourceFields()
        {
            using (new LoadingModeResource(this))
            {
                _dataTextFieldCombo.SelectedIndex = -1;
                _dataTextFieldCombo.Items.Clear();
                _dataTextFieldCombo.EnsureNotSetItem();

                _dataValueFieldCombo.SelectedIndex = -1;
                _dataValueFieldCombo.Items.Clear();
                _dataValueFieldCombo.EnsureNotSetItem();

                if (_currentDataSource != null)
                {
                    PropertyDescriptorCollection fields = _currentDataSource.Fields;

                    if (fields != null)
                    {
                        IEnumerator fieldEnum = fields.GetEnumerator();
                        while (fieldEnum.MoveNext())
                        {
                            PropertyDescriptor fieldDesc = (PropertyDescriptor)fieldEnum.Current;

                            if (BaseDataList.IsBindableType(fieldDesc.PropertyType))
                            {
                                _dataTextFieldCombo.AddItem(fieldDesc.Name);
                                _dataValueFieldCombo.AddItem(fieldDesc.Name);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Returns the index of the row that has the given PropertyDescriptor.
        /// </summary>
        /// <param name="property">Returns the index of the row that has the given PropertyDescriptor.</param>
        /// <param name="key">The value of the property parameter to search for. </param>
        /// <returns>The index of the row that has the given PropertyDescriptor.</returns>
        internal int Find(System.ComponentModel.PropertyDescriptor property, object key)
        {
            int idx    = 0;
            int result = -1;

            for (idx = 0; idx <= this.Count - 1; idx++)
            {
                object value = property.GetValue(this[idx]);
                switch (property.Name)
                {
                case "ValueToString":
                    if ((value == key))
                    {
                        result = idx;
                    }
                    break;

                default:
                    if ((value == key))
                    {
                        result = idx;
                    }
                    break;
                }

                if ((result != -1))
                {
                    return(result);
                }
            }
            return(0);
        }
Exemple #10
0
        public static List <PropertyInfo> GetBrowsableAttributes(Type type)
        {
            try
            {
                List <PropertyInfo> pInfos = new List <PropertyInfo>();

//                Type type = obj.GetType();

                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(type);

                foreach (PropertyInfo pInfo in type.GetProperties())
                {
                    System.ComponentModel.PropertyDescriptor myProperty = properties.Find(pInfo.Name, false);
                    if (!object.ReferenceEquals(null, myProperty) && myProperty.IsBrowsable)
                    {
                        pInfos.Add(pInfo);
                    }
                }

                return(pInfos);
            }
            catch
            {
                throw;
            }
        }
 public ValueTypeChainItem(PropertyDescriptor propertyDescriptor,
     object value, object target)
 {
     PropertyDescriptor = propertyDescriptor;
     Value = value;
     Target = target;
 }
 protected virtual ModelMetadata GetMetadataForProperty(Func<object> modelAccessor, Type containerType, PropertyDescriptor propertyDescriptor)
 {
     IEnumerable<Attribute> attributes = FilterAttributes(containerType, propertyDescriptor, new AttributeList(propertyDescriptor.Attributes));
     ModelMetadata result = CreateMetadata(attributes, containerType, modelAccessor, propertyDescriptor.PropertyType, propertyDescriptor.Name);
     ApplyMetadataAwareAttributes(attributes, result);
     return result;
 }
        protected override object GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder)
        {
            var propertyType = propertyDescriptor.PropertyType;

            // Check if the property type is an enum with the flag attribute
            if (propertyType.IsEnum && propertyType.GetCustomAttributes(true).Any())
            {
                var providerValue = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
                if (providerValue != null)
                {
                    var value = providerValue.RawValue;
                    if (value != null)
                    {
                        // In case it is a checkbox list/dropdownlist/radio button list
                        if (value is string[])
                        {
                            // Create flag value from posted values
                            int flagValue = 0;
                            foreach (string val in ((string[])value))
                            {
                                flagValue = flagValue | (int)Enum.Parse(propertyType, val);
                            }
                            return Enum.ToObject(propertyType, flagValue);
                        }
                        // In case it is a single value
                        if (value.GetType().IsEnum)
                        {
                            return Enum.ToObject(propertyType, value);
                        }
                    }
                }
            }
            return base.GetPropertyValue(controllerContext, bindingContext, propertyDescriptor, propertyBinder);
        }
Exemple #14
0
        public UpdateContentItemAction(IView view, IController con, ContentItem item, PropertyDescriptor property, object previousValue)
        {
            _view = view;
            _con = con;

            _state = ContentItemState.Get(item);

            var name = property.Name;
            var value = previousValue;

            if (name == "Importer")
            {
                name = "ImporterName";
                value = ((ImporterTypeDescription)value).TypeName;
            }

            if (name == "Processor")
            {
                name = "ProcessorName";
                value = ((ProcessorTypeDescription)value).TypeName;
            }

            var field = _state.GetType().GetMember(name).SingleOrDefault() as FieldInfo;
            if (field == null)
            {
                if (!_state.ProcessorParams.ContainsKey(name))
                    throw new Exception();

                _state.ProcessorParams[name] = value;
            }
            else
            {
                field.SetValue(_state, value);
            }
        }
        /// <include file='doc\DataGridGeneralPage.uex' path='docs/doc[@for="DataGridGeneralPage.LoadDataSourceFields"]/*' />
        /// <devdoc>
        /// </devdoc>
        private void LoadDataSourceFields()
        {
            EnterLoadingMode();

            dataKeyFieldCombo.SelectedIndex = -1;
            dataKeyFieldCombo.Items.Clear();
            dataKeyFieldCombo.EnsureNotSetItem();

            if (currentDataSource != null)
            {
                PropertyDescriptorCollection fields = currentDataSource.Fields;

                if (fields != null)
                {
                    IEnumerator fieldEnum = fields.GetEnumerator();
                    while (fieldEnum.MoveNext())
                    {
                        PropertyDescriptor fieldDesc = (PropertyDescriptor)fieldEnum.Current;

                        if (BaseDataList.IsBindableType(fieldDesc.PropertyType))
                        {
                            dataKeyFieldCombo.AddItem(fieldDesc.Name);
                        }
                    }
                }
            }

            ExitLoadingMode();
        }
        public void SetUp()
        {
            _archetype = ContentHelpers.Archetype;

            var content = ContentHelpers.FakeContent(123, "Fake Node 1", properties: new Collection<IPublishedProperty>
            {
                new FakePublishedProperty("myArchetypeProperty", _archetype, true)
            });

            _content = new FakeModel(content);
            _propertyDescriptor = TypeDescriptor.GetProperties(_content)["TextString"];

            _context = new FakeDittoValueResolverContext(_content, _propertyDescriptor);

            var mockedPropertyService = new Mock<PropertyValueService>();

            mockedPropertyService.SetupSequence(
                i =>
                    i.Set(It.IsAny<IPublishedContent>(), It.IsAny<CultureInfo>(), It.IsAny<PropertyInfo>(),
                        It.IsAny<object>(), It.IsAny<object>(), It.IsAny<DittoValueResolverContext>()))
                        .Returns(new HtmlString("<p>This is the <strong>summary</strong> text.</p>"))
                        .Returns("Ready to Enroll?")
                        .Returns("{}");

            _sut = new ArchetypeBindingService(mockedPropertyService.Object, new DittoAliasLocator());
        }
        private static bool AllowPropertyUpdate(PropertyDescriptor property)
        {
            if (property.IsReadOnly && !CanUpdateReadonlyTypedReference(property.PropertyType))
                return false;

			return !property.Attributes.OfType<SkipBindingAttribute>().Any();
        }
Exemple #18
0
        /// <include file='doc\HtmlControlDesigner.uex' path='docs/doc[@for="HtmlControlDesigner.PreFilterProperties"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Allows a designer to filter the set of member attributes
        ///       that the component it is designing will expose through the <see cref='System.ComponentModel.TypeDescriptor'/>
        ///       object.
        ///    </para>
        /// </devdoc>
        protected override void PreFilterProperties(IDictionary properties) {
            base.PreFilterProperties(properties);
            
            PropertyDescriptor prop = (PropertyDescriptor)properties["Name"];
            if (prop != null) {
                properties["Name"] = TypeDescriptor.CreateProperty(prop.ComponentType, prop, BrowsableAttribute.No);
            }

            prop = (PropertyDescriptor)properties["Modifiers"];
            if (prop != null) {
                properties["Modifiers"] = TypeDescriptor.CreateProperty(prop.ComponentType, prop, BrowsableAttribute.No);
            }

            properties["DataBindings"] =
                TypeDescriptor.CreateProperty(this.GetType(), "DataBindings", typeof(DataBindingCollection),
                                              new Attribute[] {
                                                  DesignerSerializationVisibilityAttribute.Hidden,
                                                  CategoryAttribute.Data,
                                                  new EditorAttribute(typeof(DataBindingCollectionEditor), typeof(UITypeEditor)),
                                                  new TypeConverterAttribute(typeof(DataBindingCollectionConverter)),
                                                  new ParenthesizePropertyNameAttribute(true),
                                                  MergablePropertyAttribute.No,
                                                  new DescriptionAttribute(SR.GetString(SR.Control_DataBindings))
                                              });
        }
Exemple #19
0
 /// <summary>
 /// Resets the property on objects</summary>
 /// <param name="owners">Objects whose property is reset</param>
 /// <param name="descriptor">Property to reset</param>
 public static void ResetProperty(IEnumerable <object> owners, PropertyDescriptor descriptor)
 {
     foreach (object owner in owners)
     {
         descriptor.ResetValue(owner);
     }
 }
 public SortExpression(string propertyName, ListSortDirection sortDirection)
 {
     PropertyName = propertyName;
     SortDirection = sortDirection;
     PropertyDescriptor = null;
     _propertyValueCache = new Hashtable();
 }
 public static CustomProperty CreateCustomProperty(IServiceProvider serviceProvider, string customPropertyName, PropertyDescriptor propertyDescriptor, object propertyOwner)
 {
     CustomProperty property = new CustomProperty(serviceProvider) {
         Name = customPropertyName
     };
     if (TypeProvider.IsAssignable(typeof(ActivityBind), propertyDescriptor.PropertyType))
     {
         System.Type type = PropertyDescriptorUtils.GetBaseType(propertyDescriptor, propertyOwner, serviceProvider);
         if (type == null)
         {
             throw new InvalidOperationException(SR.GetString("Error_CantDeterminePropertyBaseType", new object[] { propertyDescriptor.Name }));
         }
         property.Type = type.FullName;
     }
     else
     {
         property.Type = propertyDescriptor.PropertyType.FullName;
     }
     if (propertyDescriptor is ActivityBindPropertyDescriptor)
     {
         DependencyProperty property2 = DependencyProperty.FromName(propertyDescriptor.Name, propertyDescriptor.ComponentType);
         property.IsEvent = (property2 != null) && property2.IsEvent;
     }
     property.Category = propertyDescriptor.Category;
     return property;
 }
		public LocalizedPropertyDescriptor(PropertyDescriptor basePropertyDescriptor) : base(basePropertyDescriptor)
		{
			LocalizedPropertyAttribute localizedPropertyAttribute = null;
			
			foreach (Attribute attr in basePropertyDescriptor.Attributes) {
				localizedPropertyAttribute = attr as LocalizedPropertyAttribute;
				if (localizedPropertyAttribute != null) {
					break;
				}
			}
			
			if (localizedPropertyAttribute != null) {
				localizedName        = localizedPropertyAttribute.Name;
				localizedDescription = localizedPropertyAttribute.Description;
				localizedCategory    = localizedPropertyAttribute.Category;
			} else {
				localizedName        = basePropertyDescriptor.Name;
				localizedDescription = basePropertyDescriptor.Description;
				localizedCategory    = basePropertyDescriptor.Category;
			}
			
			this.basePropertyDescriptor = basePropertyDescriptor;
			
			// "Booleans" get a localized type converter
			if (basePropertyDescriptor.PropertyType == typeof(System.Boolean)) {
				customTypeConverter = new BooleanTypeConverter();
			}
		}
 public MetadataPropertyDescriptorWrapper(PropertyDescriptor descriptor, Attribute[] newAttributes)
     : base(descriptor, newAttributes)
 {
     _descriptor = descriptor;
     var readOnlyAttribute = newAttributes.OfType<ReadOnlyAttribute>().FirstOrDefault();
     _isReadOnly = (readOnlyAttribute != null ? readOnlyAttribute.IsReadOnly : false);
 }
Exemple #24
0
		/// <summary>
		/// This takes care of the actual value-change of the property.
		/// </summary>
		/// <param name="itdc">Standard ITypeDescriptorContext object.</param>
		/// <param name="isp">Standard IServiceProvider object.</param>
		/// <param name="value">The value as an object.</param>
		/// <returns>The new value as an object.</returns>
		public override object EditValue(ITypeDescriptorContext itdc, IServiceProvider isp, object value)
		{
			if(itdc != null && itdc.Instance != null && isp != null) 
			{
				iwfes = (IWindowsFormsEditorService)isp.GetService(typeof(IWindowsFormsEditorService));

				if(iwfes != null)
				{
					HatchStyle hs = HatchStyle.Weave;

					//if(itdc.PropertyDescriptor.GetValue(itdc.Instance) is HatchStyle)
					if(value is HatchStyle)
					{
						hs = (HatchStyle)itdc.PropertyDescriptor.GetValue(itdc.Instance);
						pd = itdc.PropertyDescriptor;
						oInstance = itdc.Instance;
					}

					//EditorHatchStyleUI ehsui = new EditorHatchStyleUI(hs, Color.White, Color.Black); //FIX THIS XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
					EditorHatchStyleUI ehsui = new EditorHatchStyleUI(HatchStyle.Trellis, Color.White, Color.Black);
					ehsui.IWFES = iwfes;
					ehsui.ITDC = itdc;
					ehsui.HatchStyle = (HatchStyle)value;
					ehsui.HatchStyleChanged += new EditorHatchStyleUI.MWHatchStyleEventHandler(ValueChanged);

					iwfes.DropDownControl(ehsui);
					value = ehsui.HatchStyle;
				}
			}

			return value;
		}
        protected override void SetProperty(
            ControllerContext controllerContext,
            ModelBindingContext bindingContext,
            PropertyDescriptor propertyDescriptor,
            object value)
        {
            base.SetProperty(controllerContext, bindingContext, propertyDescriptor, value);

            switch (propertyDescriptor.Name)
            {
                case "ClientName":
                    if (string.IsNullOrWhiteSpace((string)value))
                        bindingContext.ModelState.AddModelError("ClientName", "Please enter your name [binder]");
                    break;

                case "Date":
                    if (bindingContext.ModelState.IsValidField("Date") && DateTime.Now.Date > (DateTime)value)
                        bindingContext.ModelState.AddModelError("Date", "Please enter a date in the future [binder]");
                    break;

                case "TermsAccepted":
                    if (!(bool)value)
                        bindingContext.ModelState.AddModelError("TermsAccepted", "You must accept the terms [binder]");
                    break;
            }
        }
        protected override bool OnPropertyValidating(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, object value)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException("controllerContext");
            }

            if (bindingContext == null)
            {
                throw new ArgumentNullException("bindingContext");
            }

            if (propertyDescriptor == null)
            {
                throw new ArgumentNullException("propertyDescriptor");
            }

            if (value is string && controllerContext.HttpContext.Request.ContentType.StartsWith(WebConstants.APPLICATIONJSON, StringComparison.OrdinalIgnoreCase))
            {
                if (controllerContext.Controller.ValidateRequest && bindingContext.PropertyMetadata[propertyDescriptor.Name].RequestValidationEnabled)
                {
                    int index;

                    if (IsDangerousString(value.ToString(), out index))
                    {
                        throw new HttpRequestValidationException("Dangerous Input Detected");
                    }
                }
            }

            return base.OnPropertyValidating(controllerContext, bindingContext, propertyDescriptor, value);
        }
        public IEnumerable<ModelValidationResult> ValidateObject(object model, ControllerContext controllerContext, bool markProperties=true)
        {
            var results = new List<ModelValidationResult>();
            var properties = GetTypeDescriptor(model.GetType()).GetProperties();
            var props = new PropertyDescriptor[properties.Count];
            properties.CopyTo(props, 0);
            foreach (var prop in props)
            {
                var metadata = ModelMetadataProviders.Current.GetMetadataForProperty(null , model.GetType(), prop.Name);
                metadata.Model = prop.GetValue(model);
                metadata.IsRequired = false;
                var validators = this.GetValidators(metadata, controllerContext);

                foreach (var validator in validators)
                {
                    var validationResult = validator.Validate(model).ToList();
                    if(markProperties)
                        foreach (var res in validationResult)
                            res.MemberName = prop.Name;
                    results.AddRange(validationResult);
                }
            }

            return results;
        }
 public string GetDescription(PropertyDescriptor descriptor)
 {
     var description = GetResourceDescription(descriptor.ComponentType, descriptor.Name);
     if (description != null)
         return description;
     return UsageDescriptionProvider.Default.GetDescription(descriptor);
 }
		public CustomPropertyDescriptor(
			PropertyDescriptor propertyDescriptor, 
			PropertyCustomisation customisation) : base(propertyDescriptor)
		{
			_basePropertyDescriptor=propertyDescriptor;
			_customisation = customisation ;
		}
Exemple #30
0
        /// <summary>
        /// Publish Dependant Component Changes
        /// </summary>
        /// <typeparam name="T">Type of property</typeparam>
        /// <param name="propertyName">Property Name that has changed</param>
        /// <param name="value">new value for Property</param>
        private void PublishDependentComponentChanges <T>(string propertyName, T value)
        {
            System.ComponentModel.Design.IComponentChangeService changeService = null;
            System.ComponentModel.PropertyDescriptor             property      = null;
            T currentValue = default(T);

            if (DesignMode && this.Site != null)
            {
                property      = System.ComponentModel.TypeDescriptor.GetProperties(this)[propertyName];
                changeService = (System.ComponentModel.Design.IComponentChangeService) this.Site.GetService(typeof(System.ComponentModel.Design.IComponentChangeService));

                if (changeService != null)
                {
                    currentValue = (T)property.GetValue(this);

                    if (currentValue == null)
                    {
                        currentValue = default(T);
                    }

                    // Trap any error and ignore it
                    changeService.OnComponentChanging(this, property);

                    // try to set new value
                    property.SetValue(this, value);
                    changeService.OnComponentChanged(this, property, currentValue, value);
                }
            }
        }
 /// <devdoc>
 ///     Creates a new ExtenderProvidedPropertyAttribute.
 /// </devdoc>
 internal static ExtenderProvidedPropertyAttribute Create(PropertyDescriptor extenderProperty, Type receiverType, IExtenderProvider provider) {
     ExtenderProvidedPropertyAttribute e = new ExtenderProvidedPropertyAttribute();
     e.extenderProperty = extenderProperty;
     e.receiverType = receiverType;
     e.provider = provider;
     return e;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 public PropertyChangedCommand(object obj, PropertyDescriptor descriptor, object oldValue, object newValue)
 {
     mObject = obj;
     mDescriptor = descriptor;
     mOldValue = oldValue;
     mNewValue = newValue;
 }
 /// <summary>
 /// Initializes the command after the property was first changed.
 /// </summary>
 /// <param name="target">The object the property belongs to.</param>
 /// <param name="property">The property that was changed.</param>
 /// <param name="oldValue">The property's old value.</param>
 /// <param name="newValue">The property's current value.</param>
 public PropertyChangedCommand(object target, PropertyDescriptor property, object oldValue, object newValue)
 {
     _target = target;
     _property = property;
     _oldValue = oldValue;
     _newValue = newValue;
 }
Exemple #34
0
        protected override void OnSortingRangeRows(SortRangeRowsEventArgs e)
        {
            base.OnSortingRangeRows(e);

            if (DataSource == null || DataSource.AllowSort == false)
            {
                return;
            }

            System.ComponentModel.PropertyDescriptor propertyCol = Columns[e.KeyColumn].PropertyColumn;

            if (propertyCol != null)
            {
                ListSortDirection direction;
                if (e.Ascending)
                {
                    direction = ListSortDirection.Ascending;
                }
                else
                {
                    direction = ListSortDirection.Descending;
                }
                ListSortDescription[] sortsArray = new ListSortDescription[1];
                sortsArray[0] = new ListSortDescription(propertyCol, direction);

                DataSource.ApplySort(new ListSortDescriptionCollection(sortsArray));
            }
            else
            {
                DataSource.ApplySort(null);
            }
        }
Exemple #35
0
 public Type GetElementType(PropertyDescriptor[] listAccessors)
 {
     PropertyDescriptor descriptor = listAccessors[0];
     foreach (DSPropertyDescriptor descriptor2 in this._TableDesc)
     {
         if (descriptor2.Name == descriptor.Name)
         {
             if (listAccessors.Length == 1)
             {
                 return descriptor2.ComponentType;
             }
             Type componentType = descriptor2.ComponentType;
             for (int i = 1; i < listAccessors.Length; i++)
             {
                 PropertyInfo property = componentType.GetProperty(listAccessors[1].Name);
                 if (property == null)
                 {
                     return null;
                 }
                 property = property.PropertyType.GetProperty("Item");
                 if (property == null)
                 {
                     return null;
                 }
                 componentType = property.PropertyType;
             }
             return componentType;
         }
     }
     return null;
 }
 /// <summary>
 /// Gets the rules the adapter provides.
 /// </summary>
 /// <param name="attribute">The <see cref="ValidationAttribute"/> that should be handled.</param>
 /// <param name="descriptor">A <see cref="PropertyDescriptor"/> instance for the property that is being validated.</param>
 /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ModelValidationRule"/> instances.</returns>
 public override IEnumerable<ModelValidationRule> GetRules(ValidationAttribute attribute, PropertyDescriptor descriptor)
 {
     yield return new StringLengthValidationRule(attribute.FormatErrorMessage,
         new[] { descriptor.Name },
         ((StringLengthAttribute)attribute).MinimumLength,
         ((StringLengthAttribute)attribute).MaximumLength);
 }
Exemple #37
0
 /// <summary>
 /// Gets whether two property descriptors should be considered equal, for the purposes of ATF
 /// property editing. The default .NET Equals() method doesn't take into account the Category.</summary>
 /// <param name="a">First PropertyDescriptor to compare</param>
 /// <param name="b">Second PropertyDescriptor to compare</param>
 /// <returns>True iff PropertyDescriptors equal, i.e., the name, category and type are the same</returns>
 public static bool PropertyDescriptorsEqual(PropertyDescriptor a, PropertyDescriptor b)
 {
     return
         (a.Name == b.Name &&
          GetCategoryName(a) == GetCategoryName(b) &&
          a.PropertyType == b.PropertyType);
 }
		public static PropertyDescriptorCollection GetProperties(Type memberType)
		{
			if (memberType == null)
				return PropertyDescriptorCollection.Empty;

			PropertyDescriptorCollection pdc;
			if ((pdc = (PropertyDescriptorCollection) collections[memberType]) != null)
				return (pdc);
 
			PropertyInfo[] allProps = memberType.GetProperties();
			int l = allProps.Length;
			for (int i = 0; i < allProps.Length; i++)
			{
				PropertyInfo pi = allProps[i];
				if (!IsAllowedProperty(pi.Name))
				{
					allProps[i] = null;
					l--;
				}
			}

			PropertyDescriptor[] descriptors = new PropertyDescriptor[l];
			
			int j = 0;
			foreach(PropertyInfo pinfo in allProps)
			{
				if (pinfo != null)
				{
					descriptors[j++] = new ExtendedPropertyDescriptor(pinfo.Name, memberType, pinfo.PropertyType);
				}		
			}								 
			PropertyDescriptorCollection result = new PropertyDescriptorCollection(descriptors);
			collections.Add(memberType, result);
			return result;			
		}
        /// <summary>
        /// Method to get the attempted value for the property and to execute the callback method to retreive the 'real' value,
        /// then set the property whilst executing the correct events.
        /// The event order is based on how the DefaultModelBinder sets properties so figured I'd go with these 'best practices'.
        /// </summary>
        /// <param name="controllerContext"></param>
        /// <param name="bindingContext"></param>
        /// <param name="propertyDescriptor"></param>
        /// <param name="getValue">callback method to get the 'real' value</param>        
        protected internal void SetPropertyValue(ControllerContext controllerContext,
                                        ModelBindingContext bindingContext,
                                        PropertyDescriptor propertyDescriptor,
                                        Func<string, object> getValue)
        {
            var valueObject = bindingContext.ValueProvider.GetValue(propertyDescriptor.Name);
            if (valueObject != null)
            {
                var val = valueObject.AttemptedValue;
                //get the real value from the callback
                var realVal = getValue.Invoke(val);

                //add the bound value to model state if it's not already there, generally only simple props will be there
                if (!bindingContext.ModelState.ContainsKey(propertyDescriptor.Name))
                {
                    bindingContext.ModelState.Add(propertyDescriptor.Name, new ModelState());
                    bindingContext.ModelState.SetModelValue(propertyDescriptor.Name, new ValueProviderResult(realVal, val, null));
                }

                //set the value
                if (OnPropertyValidating(controllerContext, bindingContext, propertyDescriptor, realVal))
                {
                    SetProperty(controllerContext, bindingContext, propertyDescriptor, realVal);
                    OnPropertyValidated(controllerContext, bindingContext, propertyDescriptor, realVal);
                    return;
                }
            }
        }
    /// <summary>
    /// Retourne la collection des propriétés à afficher pour l'objet
    /// </summary>
    /// <remarks>
    /// Cette méthode ajoute le descripteur de la propriété "Name" uniquement pour les objets qui sont au moins <see cref="Control"/>.
    /// </remarks>
    /// <param name="component">objet dont les propriétés sont à afficher</param>
    /// <param name="attributes">null ou tableau de filtrage selon les attributs</param>
    /// <returns>la collection des descripteurs des propriétés à afficher</returns>
    public override PropertyDescriptorCollection GetProperties( object component, System.Attribute[] attributes ) {
      PropertyDescriptorCollection properties;

      // récupérer le propriétés à partir du descripteur de type
      if ( attributes == null ) attributes = DefaultFilter ;
      properties = TypeDescriptor.GetProperties( component, attributes );

      // l'objet dont les propriétés sont à afficher n'est pas Control --> rien d'autre à faire
      if (! (component is Control) ) return properties;

      // si la propriété Name figure déjà dans la collection --> rien d'autre à faire
      PropertyDescriptor oldDescriptorOfName = properties.Find( "Name", false ) ;
      if (oldDescriptorOfName != null) return properties ;

      // rechercher le descripteur de la propriété Name dans la collection de tous les descripteurs de propriétés
      PropertyDescriptorCollection allProperties = TypeDescriptor.GetProperties( component );
      oldDescriptorOfName = allProperties.Find( "Name", false );
      if ( oldDescriptorOfName == null ) return properties;

      // composer le nouveau descripteur de la propriété Name
      PropertyDescriptor newDescriptorOfName = TypeDescriptor.CreateProperty( oldDescriptorOfName.ComponentType, oldDescriptorOfName, new ParenthesizePropertyNameAttribute( true ), CategoryAttribute.Design );
      //PropertyDescriptor newDescriptorOfName = TypeDescriptor.CreateProperty( oldDescriptorOfName.ComponentType, oldDescriptorOfName, BrowsableAttribute.Yes, new ParenthesizePropertyNameAttribute( true ), CategoryAttribute.Design );
      
      // composer la collection des descripteurs de propriétés obtenu en ajoutant le descripteur de la propriété Name
      PropertyDescriptor[] propertiesArray = new PropertyDescriptor[ properties.Count ];
      properties.CopyTo( propertiesArray, 0 );
      properties = new PropertyDescriptorCollection( propertiesArray );
      properties.Add( newDescriptorOfName );
      return properties;
    }
Exemple #41
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:SiliconStudio.Core.TypeConverters.Half2Converter" /> class.
 /// </summary>
 public Half2Converter()
 {
     Type type = typeof (Half2);
     PropertyDescriptor[] propArray = new PropertyDescriptor[]
                                          {new FieldPropertyDescriptor(type.GetField("X")), new FieldPropertyDescriptor(type.GetField("Y"))};
     properties = new PropertyDescriptorCollection(propArray);
 }
Exemple #42
0
        /// <summary>
        ///    <para>Gets a collection of properties for the type of array specified by the value parameter.</para>
        /// </summary>
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            if (value == null)
            {
                return null;
            }

            PropertyDescriptor[] props = null;

            if (value.GetType().IsArray)
            {
                Array valueArray = (Array)value;
                int length = valueArray.GetLength(0);
                props = new PropertyDescriptor[length];

                Type arrayType = value.GetType();
                Type elementType = arrayType.GetElementType();

                for (int i = 0; i < length; i++)
                {
                    props[i] = new ArrayPropertyDescriptor(arrayType, elementType, i);
                }
            }

            return new PropertyDescriptorCollection(props);
        }
 public SortExpression(string propertyName)
 {
     PropertyName = propertyName;
     SortDirection = ListSortDirection.Ascending;
     PropertyDescriptor = null;
     _propertyValueCache = new Hashtable();
 }
        protected virtual IEnumerable<Attribute> FilterAttributes(Type containerType, PropertyDescriptor propertyDescriptor, IEnumerable<Attribute> attributes) {
            if (typeof(ViewPage).IsAssignableFrom(containerType) || typeof(ViewUserControl).IsAssignableFrom(containerType)) {
                return attributes.Where(a => !(a is ReadOnlyAttribute));
            }

            return attributes;
        }
 public BindablePropertyNode(System.ComponentModel.PropertyDescriptor propDesc, ExpressionBinding binding)
 {
     this._binding   = binding;
     this._propDesc  = propDesc;
     this._isValid   = true;
     base.Text       = propDesc.Name;
     base.ImageIndex = base.SelectedImageIndex = this.IsBound ? (this.IsGenerated ? 2 : 1) : 0;
 }
Exemple #46
0
 public DataGridColumnStyle(System.ComponentModel.PropertyDescriptor prop) : this()
 {
     this.PropertyDescriptor = prop;
     if (prop != null)
     {
         this.readOnly = prop.IsReadOnly;
     }
 }
Exemple #47
0
 // Helper method to safely set a component’s property
 private void SetProperty(string propertyName, object value)
 {
     // Get property
     System.ComponentModel.PropertyDescriptor property
         = System.ComponentModel.TypeDescriptor.GetProperties(this.Panel)[propertyName];
     // Set property value
     property.SetValue(this.Panel, value);
 }
Exemple #48
0
        /// <summary>
        /// Obtains the default properties for an object</summary>
        /// <param name="owner">Object whose properties are obtained</param>
        /// <returns>Default properties for an object, as an array</returns>
        public static PropertyDescriptor[] GetDefaultProperties2(object owner)
        {
            PropertyDescriptorCollection propertyCollection = GetDefaultProperties(owner);

            PropertyDescriptor[] result = new PropertyDescriptor[propertyCollection.Count];
            propertyCollection.CopyTo(result, 0);
            return(result);
        }
Exemple #49
0
 internal DataGridColumnStyle(System.ComponentModel.PropertyDescriptor prop, bool isDefault) : this(prop)
 {
     this.isDefault = isDefault;
     if (isDefault)
     {
         this.headerName  = prop.Name;
         this.mappingName = prop.Name;
     }
 }
Exemple #50
0
        public void Sort(string PropertyName, ListSortDirection direction)
        {
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));

            System.ComponentModel.PropertyDescriptor myProperty = properties.Find(PropertyName, false);
            if (myProperty != null)
            {
                ((IBindingList)this).ApplySort(myProperty, direction);
            }
        }
Exemple #51
0
        PropertyDescriptorCollection ITypedList.GetItemProperties(System.ComponentModel.PropertyDescriptor[] listAccessors)
        {
            System.Collections.ArrayList descriptors = new System.Collections.ArrayList();
            descriptors.Add(new PropertyDescriptor("Name"));
            descriptors.Add(new PropertyDescriptor("Address"));
            descriptors.Add(new PropertyDescriptor("Address_City"));

            System.ComponentModel.PropertyDescriptor[] propertyDescriptors = new System.ComponentModel.PropertyDescriptor[descriptors.Count];
            descriptors.CopyTo(propertyDescriptors, 0);
            return(new PropertyDescriptorCollection(propertyDescriptors));
        }
Exemple #52
0
        public System.ComponentModel.EventDescriptor GetEvent(System.ComponentModel.PropertyDescriptor property)
        {
            EventPropertyDescriptor epd = property as EventPropertyDescriptor;

            if (epd == null)
            {
                return(null);
            }

            return(epd.InternalEventDescriptor);
        }
Exemple #53
0
        /// <summary>
        /// Obtains a property's category name</summary>
        /// <param name="descriptor">Property descriptor</param>
        /// <returns>Property's category name; "Misc" if none is defined by the descriptor</returns>
        public static string GetCategoryName(PropertyDescriptor descriptor)
        {
            string result = descriptor.Category;

            if (result == null)
            {
                result = "Misc".Localize("Miscellaneous category");
            }

            return(result);
        }
Exemple #54
0
 /// <summary>
 /// Gets a hash code for a property descriptor that allows different PropertyDescriptor
 /// objects to be considered equivalent if their name, category, and property type match</summary>
 /// <param name="propertyDescriptor">Property descriptor to get hash code for</param>
 /// <returns>Hash code for property descriptor</returns>
 /// <remarks>Consider using GetPropertyDescriptorKey() instead, to avoid any chance of
 /// collisions, since it's not really appropriate to compare hash codes alone when
 /// determining equality.</remarks>
 public static int GetPropertyDescriptorHash(this PropertyDescriptor propertyDescriptor)
 {
     // Different PropertyDescriptor objects need to have the same hash code if the Name
     //  and Category and PropertyType match. Note that 'Name' and 'Category' can be equal
     //  to each other, so we can't xor their hash codes together. Note that Category can be null.
     // http://tracker.ship.scea.com/jira/browse/WWSATF-1051
     return
         (propertyDescriptor.Name.GetHashCode() ^
          (GetCategoryName(propertyDescriptor).GetHashCode() << 8) ^
          propertyDescriptor.PropertyType.GetHashCode());
 }
 public void ApplySort(System.ComponentModel.PropertyDescriptor pd, System.ComponentModel.ListSortDirection direction)
 {
     if (_list.SupportsSorting)
     {
         _list.ApplySort(pd, direction);
     }
     else
     {
         ApplySort(new ListSortDescriptionCollection(new ListSortDescription[] { new ListSortDescription(pd, direction) }));
     }
 }
        /// <summary>
        /// Determines whether the property is read-only.
        /// </summary>
        /// <param name="pd">The property descriptor.</param>
        /// <returns><c>true</c> if the property is read-only; otherwise, <c>false</c>.</returns>
        public static bool IsReadOnly(this System.ComponentModel.PropertyDescriptor pd)
        {
            var a = pd.GetFirstAttributeOrDefault <ReadOnlyAttribute>();

            if (a != null)
            {
                return(a.IsReadOnly);
            }

            return(pd.IsReadOnly);
        }
        /// <summary>
        /// Gets the category for the specified property.
        /// </summary>
        /// <param name="pd">The property descriptor.</param>
        /// <returns>The category.</returns>
        public static string GetCategory(this System.ComponentModel.PropertyDescriptor pd)
        {
            var a = pd.GetFirstAttributeOrDefault <CategoryAttribute>();

            if (a != null)
            {
                return(a.Category);
            }

            return(pd.Category);
        }
        /// <summary>
        /// Gets the display name for the specified property.
        /// </summary>
        /// <param name="pd">The property descriptor.</param>
        /// <returns>The display name.</returns>
        public static string GetDisplayName(this System.ComponentModel.PropertyDescriptor pd)
        {
            var a = pd.GetFirstAttributeOrDefault <DisplayNameAttribute>();

            if (a != null)
            {
                return(a.DisplayName);
            }

            return(pd.DisplayName);
        }
Exemple #59
0
        /// <summary>
        /// Returns whether or not the property can be reset</summary>
        /// <param name="owners">Objects whose property is tested</param>
        /// <param name="descriptor">Property to reset</param>
        /// <returns>True iff the property can be reset on the object</returns>
        public static bool CanResetProperty(IEnumerable <object> owners, PropertyDescriptor descriptor)
        {
            foreach (object owner in owners)
            {
                if (!descriptor.CanResetValue(owner))
                {
                    return(false);
                }
            }

            return(true);
        }
		// Cannot use one PropertyDescriptor for all owners, because the
		// propertydescriptors might have different Invokees. Check
		// ReflectionPropertyDescriptor.GetInvokee and how it's used.
		//
		public GridEntry (PropertyGrid propertyGrid, PropertyDescriptor[] properties, 
				  GridEntry parent) : this (propertyGrid, parent) 
		{
			if (properties == null || properties.Length == 0)
				throw new ArgumentNullException ("prop_desc");
			property_descriptors = properties;
		}