本文整理汇总了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;
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例6: PropertyChangedCommand
/// <summary>
/// Constructor
/// </summary>
public PropertyChangedCommand(object obj, PropertyDescriptor descriptor, object oldValue, object newValue)
{
mObject = obj;
mDescriptor = descriptor;
mOldValue = oldValue;
mNewValue = newValue;
}
示例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);
}
示例8: CustomPropertyDescriptor
public CustomPropertyDescriptor(
PropertyDescriptor propertyDescriptor,
PropertyCustomisation customisation) : base(propertyDescriptor)
{
_basePropertyDescriptor=propertyDescriptor;
_customisation = customisation ;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}