当前位置: 首页>>代码示例>>C#>>正文


C# ComponentModel.PropertyDescriptor类代码示例

本文整理汇总了C#中System.ComponentModel.PropertyDescriptor的典型用法代码示例。如果您正苦于以下问题:C# PropertyDescriptor类的具体用法?C# PropertyDescriptor怎么用?C# PropertyDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PropertyDescriptor类属于System.ComponentModel命名空间,在下文中一共展示了PropertyDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetProperty

        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;
            }
        }
开发者ID:aistrate,项目名称:ProAspNetMvc3,代码行数:26,代码来源:ValidatingModelBinder.cs

示例2: GetElementType

 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;
 }
开发者ID:JamesH001,项目名称:SX1231,代码行数:31,代码来源:DSTypeDescriptor.cs

示例3: GetRules

 /// <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);
 }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:13,代码来源:StringLengthValidatorAdapter.cs

示例4: UpdateContentItemAction

        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);
            }
        }
开发者ID:KennethYap,项目名称:MonoGame,代码行数:35,代码来源:UpdateAction.cs

示例5: OnPropertyValidating

        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);
        }
开发者ID:StrixIT,项目名称:StrixIT.Platform,代码行数:32,代码来源:StrixPlatformBinder.cs

示例6: PropertyChangedCommand

 /// <summary>
 /// Constructor
 /// </summary>
 public PropertyChangedCommand(object obj, PropertyDescriptor descriptor, object oldValue, object newValue)
 {
     mObject = obj;
     mDescriptor = descriptor;
     mOldValue = oldValue;
     mNewValue = newValue;
 }
开发者ID:RasterCode,项目名称:OtterUI,代码行数:10,代码来源:PropertyChangedCommand.cs

示例7: GetPropertyValue

        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);
        }
开发者ID:IDM3,项目名称:CharecterSheetTracker,代码行数:34,代码来源:Global.asax.cs

示例8: CustomPropertyDescriptor

		public CustomPropertyDescriptor(
			PropertyDescriptor propertyDescriptor, 
			PropertyCustomisation customisation) : base(propertyDescriptor)
		{
			_basePropertyDescriptor=propertyDescriptor;
			_customisation = customisation ;
		}
开发者ID:SteveDunn,项目名称:oglr,代码行数:7,代码来源:CustomPropertyDescriptor.cs

示例9: Create

 /// <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;
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:10,代码来源:ExtenderProvidedPropertyAttribute.cs

示例10: LocalizedPropertyDescriptor

		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();
			}
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:28,代码来源:LocalizedPropertyDescriptor.cs

示例11: ValidateObject

        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;
        }
开发者ID:avannini,项目名称:uisp-mobile,代码行数:25,代码来源:LocalizedModelValidatorProvider.cs

示例12: CreateCustomProperty

 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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:CustomProperty.cs

示例13: MetadataPropertyDescriptorWrapper

 public MetadataPropertyDescriptorWrapper(PropertyDescriptor descriptor, Attribute[] newAttributes)
     : base(descriptor, newAttributes)
 {
     _descriptor = descriptor;
     var readOnlyAttribute = newAttributes.OfType<ReadOnlyAttribute>().FirstOrDefault();
     _isReadOnly = (readOnlyAttribute != null ? readOnlyAttribute.IsReadOnly : false);
 }
开发者ID:expanz,项目名称:expanz-Microsoft-XAML-SDKs,代码行数:7,代码来源:MetadataPropertyDescriptorWrapper.cs

示例14: EditValue

		/// <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;
		}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:39,代码来源:EditorHatchStyle.cs

示例15: BindProperty

        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;
            }
        }
开发者ID:Joebeazelman,项目名称:rebelcmsxu5,代码行数:25,代码来源:UrlPickerPreValueModelBinder.cs


注:本文中的System.ComponentModel.PropertyDescriptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。