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


C# PropertyDescriptor.GetValue方法代码示例

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


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

示例1: ProcessProperty

 /// <summary>
 /// Processes the property.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="property">The property.</param>
 private static void ProcessProperty(object value, PropertyDescriptor property)
 {
     if (property.Attributes.Contains(AntiXssHtmlText))
     {
         property.SetValue(value, Sanitizer.GetSafeHtmlFragment((string) property.GetValue(value)));
     }
     else if (property.Attributes.Contains(AntiXssIgnore))
     {
         // do nothing this contains special text
     }
     else
     {
         property.SetValue(value, HttpUtility.HtmlDecode(HttpUtility.HtmlEncode((string)property.GetValue(value))));
     }
 }
开发者ID:vlko,项目名称:vlko,代码行数:20,代码来源:AntiXssAttribute.cs

示例2: GetValidationErrorsForProperty

 private IEnumerable<ValidationError> GetValidationErrorsForProperty(PropertyDescriptor property, object model)
 {
     return property.Attributes
         .OfType<ValidationAttribute>()
         .Where(x => !x.IsValid(property.GetValue(model)))
         .Select(x => new ValidationError(property.Name, x.FormatErrorMessage(string.Empty), model));
 }
开发者ID:gosuto,项目名称:tfs2.com,代码行数:7,代码来源:DataAnnotationsValidator.cs

示例3: GetPropertyValue

 private object GetPropertyValue(IDesignerSerializationManager manager, PropertyDescriptor property, object value, out bool validValue)
 {
     object obj2 = null;
     validValue = true;
     try
     {
         if (!property.ShouldSerializeValue(value))
         {
             AmbientValueAttribute attribute = (AmbientValueAttribute) property.Attributes[typeof(AmbientValueAttribute)];
             if (attribute != null)
             {
                 return attribute.Value;
             }
             DefaultValueAttribute attribute2 = (DefaultValueAttribute) property.Attributes[typeof(DefaultValueAttribute)];
             if (attribute2 != null)
             {
                 return attribute2.Value;
             }
             validValue = false;
         }
         obj2 = property.GetValue(value);
     }
     catch (Exception exception)
     {
         validValue = false;
         manager.ReportError(System.Design.SR.GetString("SerializerPropertyGenFailed", new object[] { property.Name, exception.Message }));
     }
     return obj2;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:PropertyMemberCodeDomSerializer.cs

示例4: ProcessProperty

 /// <summary>
 /// Processes the property.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="property">The property.</param>
 private static void ProcessProperty(object value, PropertyDescriptor property)
 {
     if (property.Attributes.Contains(AntiXssHtmlText))
     {
         property.SetValue(value, AntiXss.GetSafeHtmlFragment((string) property.GetValue(value)));
     }
 }
开发者ID:vlko,项目名称:jobs,代码行数:12,代码来源:AntiXssAttribute.cs

示例5: EnumPropertyItem

 public EnumPropertyItem(PropertyDescriptor property, object instance, IEnumerable values)
     : base(property, instance)
 {
     EnumValues = CollectionViewSource.GetDefaultView(values);
     EnumValues.MoveCurrentTo(property.GetValue(instance));
     EnumValues.CurrentChanged += OnEnumValueChanged;
 }
开发者ID:bdurrani,项目名称:WPF-Inspector,代码行数:7,代码来源:EnumPropertyItem.cs

示例6: RelatedCurrencyManager

        public RelatedCurrencyManager(BindingManagerBase parent, PropertyDescriptor prop_desc)
            : base(prop_desc.GetValue (parent.Current))
        {
            this.parent = parent;
            this.prop_desc = prop_desc;

            parent.PositionChanged += new EventHandler (parent_PositionChanged);
        }
开发者ID:pzsysa,项目名称:gtk-sharp-forms,代码行数:8,代码来源:RelatedCurrencyManager.cs

示例7: OverlayEditBox

 public OverlayEditBox(object Obj, string propName, Point position)
 {
     InitializeComponent();
     obj = Obj;
     prop = TypeDescriptor.GetProperties(obj).Find(propName, true);
     Location = position;
     editor.Text = prop.GetValue(obj).ToString();
     InputHook.MouseDown += OnGlobalMouseDown;
 }
开发者ID:Xambey,项目名称:MAIDE,代码行数:9,代码来源:OverlayEditBox.cs

示例8: CommandPropertyItem

        public CommandPropertyItem(PropertyDescriptor property, object instance)
            : base(property, instance)
        {
            _command = property.GetValue(instance) as ICommand;
            if (_command != null)
            {
                _command.CanExecuteChanged += CanExecuteChanged;
            }

            _executeCommand = new Command<object>(o => _command.Execute(GetCommandParameter()), o => _command != null && _command.CanExecute(GetCommandParameter()));
        }
开发者ID:bdurrani,项目名称:WPF-Inspector,代码行数:11,代码来源:CommandPropertyItem.cs

示例9: Contains

 public static Func<object,bool> Contains(PropertyDescriptor property, string text)
 {
     if (string.IsNullOrEmpty(text))
     {
         return True;
     }
     return row =>
                {
                    var value = property.GetValue(row);
                    return value != null && value.ToString().IndexOf(text) >= 0;
                };
 }
开发者ID:lgatto,项目名称:proteowizard,代码行数:12,代码来源:FilterPredicate.cs

示例10: BindSelectList

 /// <summary>
 /// Binds a IEnumerable{SelectList}
 /// </summary>
 /// <param name="binder">The binder.</param>
 /// <param name="controllerContext">The controller context.</param>
 /// <param name="bindingContext">The binding context.</param>
 /// <param name="propertyDescriptor">The property descriptor.</param>
 public static void BindSelectList(this StandardModelBinder binder, ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)
 {
     var selectList = (IEnumerable<SelectListItem>)propertyDescriptor.GetValue(bindingContext.Model);
     if (selectList != null)
     {
         //first, need to zero out all selections
         selectList.UnSelectItems();
         binder.SetPropertyValue(controllerContext, bindingContext, propertyDescriptor,
                                 val =>
                                     {
                                         selectList.SelectItems(val.Split(','));
                                         return selectList;
                                     });
     }
 }
开发者ID:paulsuart,项目名称:rebelcmsxu5,代码行数:22,代码来源:ModelBinderExtensions.cs

示例11: SerializeNormalProperty

		private void SerializeNormalProperty (IDesignerSerializationManager manager, 
											  object value, PropertyDescriptor descriptor, CodeStatementCollection statements)
		{
			CodeExpression leftSide = base.SerializeToExpression (manager, value);
			CodeExpression rightSide = null;

			MemberRelationship relationship = GetRelationship (manager, value, descriptor);
			if (!relationship.IsEmpty) 
				rightSide = new CodePropertyReferenceExpression (base.SerializeToExpression (manager, relationship.Owner), 
																 relationship.Member.Name);
			else
				rightSide = base.SerializeToExpression (manager, descriptor.GetValue (value));

			statements.Add (new CodeAssignStatement (leftSide, rightSide));
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:15,代码来源:PropertyCodeDomSerializer.cs

示例12: SetProperty

        protected override void SetProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, object value)
        {
            ModelMetadata propertyMetadata = bindingContext.PropertyMetadata[propertyDescriptor.Name];
            propertyMetadata.Model = value;
            string modelStateKey = CreateSubPropertyName(bindingContext.ModelName, propertyMetadata.PropertyName);

            // Try to set a value into the property unless we know it will fail (read-only
            // properties and null values with non-nullable types)
            if (!propertyDescriptor.IsReadOnly)
            {
                try
                {
                    if (value == null)
                    {
                        propertyDescriptor.SetValue(bindingContext.Model, value);
                    }
                    else
                    {
                        Type valueType = value.GetType();

                        if (valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
                        {
                            IListSource ls = (IListSource)propertyDescriptor.GetValue(bindingContext.Model);
                            IList list = ls.GetList();

                            foreach (var item in (IEnumerable)value)
                            {
                                list.Add(item);
                            }
                        }
                        else
                        {
                            propertyDescriptor.SetValue(bindingContext.Model, value);
                        }
                    }

                }
                catch (Exception ex)
                {
                    // Only add if we're not already invalid
                    if (bindingContext.ModelState.IsValidField(modelStateKey))
                    {
                        bindingContext.ModelState.AddModelError(modelStateKey, ex);
                    }
                }
            }
        }
开发者ID:mikalai-silivonik,项目名称:bnh,代码行数:47,代码来源:BnhModelBinder.cs

示例13: BindProperty

        /// <inheritdoc/>
        protected override void BindProperty(ControllerContext controllerContext,
                                             ModelBindingContext bindingContext,
                                             PropertyDescriptor propertyDescriptor) {
            string fullPropertyKey = CreateSubPropertyName(bindingContext.ModelName, propertyDescriptor.Name);

            // Only bind properties that are part of the request
            if (bindingContext.ValueProvider.DoesAnyKeyHavePrefix(fullPropertyKey)) {
                var innerContext = new ModelBindingContext() {
                    Model = propertyDescriptor.GetValue(bindingContext.Model),
                    ModelName = fullPropertyKey,
                    ModelState = bindingContext.ModelState,
                    ModelType = propertyDescriptor.PropertyType,
                    ValueProvider = bindingContext.ValueProvider
                };
				
                IModelBinder binder = Binders.GetBinder(propertyDescriptor.PropertyType);
                object newPropertyValue = ConvertValue(propertyDescriptor, binder.BindModel(controllerContext, innerContext));
                ModelState modelState = bindingContext.ModelState[fullPropertyKey];

                // Only validate and bind if the property itself has no errors
                if (modelState.Errors.Count == 0) {
                    if (OnPropertyValidating(controllerContext, bindingContext, propertyDescriptor, newPropertyValue)) {
                        SetProperty(controllerContext, bindingContext, propertyDescriptor, newPropertyValue);
                        OnPropertyValidated(controllerContext, bindingContext, propertyDescriptor, newPropertyValue);
                    }
                }

                // There was an error getting the value from the binder, which was probably a format
                // exception (meaning, the data wasn't appropriate for the field)
                else {
                    foreach (var error in modelState.Errors.Where(err => err.ErrorMessage == "" && err.Exception != null).ToList()) {
                        for (var exception = error.Exception; exception != null; exception = exception.InnerException) {
                            if (exception is FormatException) {
                                string displayName = GetDisplayName(propertyDescriptor);
                                string errorMessage = InvalidValueFormatter(propertyDescriptor, modelState.Value.AttemptedValue, displayName);
                                modelState.Errors.Remove(error);
                                modelState.Errors.Add(errorMessage);
                                break;
                            }
                        }
                    }
                }
            }
        }
开发者ID:bunglestink,项目名称:YFSC.NET,代码行数:45,代码来源:DataAnnotationsModelBinder.cs

示例14: GetDataValue

        public override IDataValue GetDataValue(PropertyDescriptor propertyDescriptor, object data)
        {
            if (propertyDescriptor.PropertyType.IsArray && propertyDescriptor.PropertyType.GetElementType().Equals(typeof(byte)))
            {
                byte[] value = propertyDescriptor.GetValue(data) as byte[];

                if (value != null)
                {
                    return new DataValue(propertyDescriptor.Name, MySqlFunctions.Unhex(ByteArrayToHexString(value)), false);
                }
                else
                {
                    return new DataValue(propertyDescriptor.Name, null);
                }
            }
            else
            {
                return base.GetDataValue(propertyDescriptor, data);
            }
        }
开发者ID:ibebbs,项目名称:fluentmigrator,代码行数:20,代码来源:MySqlEvaluator.cs

示例15: Validate

        /// <summary>
        /// Validates the given instance.
        /// </summary>
        /// <param name="instance">The instance that should be validated.</param>
        /// <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 virtual IEnumerable<ModelValidationError> Validate(object instance, ValidationAttribute attribute, PropertyDescriptor descriptor)
        {
            var context =
                new ValidationContext(instance, null, null)
                {
                    MemberName = descriptor == null ? null : descriptor.Name
                };

            if(descriptor != null)
            {
                instance = descriptor.GetValue(instance);
            }

            var result =
                attribute.GetValidationResult(instance, context);

            if (result != null)
            {
                yield return new ModelValidationError(result.MemberNames, string.Join(" ", result.MemberNames.Select(attribute.FormatErrorMessage)));
            }
        }
开发者ID:jijamw,项目名称:Nancy,代码行数:28,代码来源:DataAnnotationsValidatorAdapter.cs


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