/// <summary>
        /// Returns the default property for this instance of a component.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.PropertyDescriptor"/> that represents the default property for this object, or null if this object does not have properties.
        /// </returns>
        PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
        {
            PropertySpecification propertySpec = this.PropertySpecifications.FirstOrDefault(p => p.Name == this.DefaultProperty);

            return(propertySpec == null ? null : new PropertySpecificationDescriptor(propertySpec, this,
                                                                                     new Attribute[] { new MergablePropertyAttribute(true) }));
        }
Example #2
0
        /// <summary>
        /// Returns whether the collection of standard values returned from <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues"/> is an exclusive list of possible values, using the specified context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context.</param>
        /// <returns>
        /// true if the <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"/> returned from <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues"/> is an exhaustive list of possible values; false if other values are possible.
        /// </returns>
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            PropertySpecification specification = GetPropSpec(context);

            if (specification == null)
            {
                Trap.trap();
                return(true);
            }
            return(!specification.IsValueListPlus);
        }
Example #3
0
        /// <summary>
        /// Returns whether this object supports a standard set of values that can be picked from a list, using the specified context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context.</param>
        /// <returns>
        /// true if <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues"/> should be called to find a common set of values the object supports; otherwise, false.
        /// </returns>
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            PropertySpecification specification = GetPropSpec(context);

            if (specification == null)
            {
                Trap.trap();
                return(true);
            }
            return(specification.ValueList != null && specification.ValueList.Count > 0);
        }
Example #4
0
        /// <summary>
        /// Returns a collection of standard values for the data type this type converter is designed for when provided with a format context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param>
        /// <returns>
        /// A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"/> that holds a standard set of valid values, or null if the data type does not support a standard set of values.
        /// </returns>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if ((context == null) || (context.PropertyDescriptor == null) || (context.PropertyDescriptor.ComponentType == null) ||
                (context.PropertyDescriptor.ComponentType != typeof(PropertySpecification)))
            {
                Trap.trap();
                return(base.GetStandardValues(context));
            }
            PropertySpecificationDescriptor specificationDescriptor = context.PropertyDescriptor as PropertySpecificationDescriptor;

            if (specificationDescriptor == null)
            {
                // check if the property descriptor is a multi-property descriptor, which is created by various property grids when multiple objects are
                // merged and displayed simultaneously.
                var itemProperty = context.PropertyDescriptor.GetType().GetProperty("Item");
                if (itemProperty == null)
                {
                    return(base.GetStandardValues(context));
                }
                try
                {
                    specificationDescriptor = itemProperty.GetValue(context.PropertyDescriptor, new object[] { 0 }) as PropertySpecificationDescriptor;
                    if (specificationDescriptor == null)
                    {
                        // give up
                        return(base.GetStandardValues(context));
                    }
                }
                catch
                {
                    // no descriptor at index 0
                    return(base.GetStandardValues(context));
                }
            }
            // check if the property descriptor is a multi-property descriptor, which is created by various property grids when multiple objects are
            PropertySpecification specification = specificationDescriptor.Specification;

            if ((specification == null) || (specification.ValueList == null) || (specification.ValueList.Count <= 0))
            {
                Trap.trap();
                // check if the property descriptor is a multi-property descriptor, which is created by various property grids when multiple objects are
                return(base.GetStandardValues(context));
            }
            // check if the property descriptor is a multi-property descriptor, which is created by various property grids when multiple objects are
            return(new StandardValuesCollection(specification.ValueList));
        }
 /// <summary>
 /// Initializes a new instance of the PropertySpecEventArgs class.
 /// </summary>
 /// <param name="property">The PropertySpec that represents the property whose value is being requested or set.</param>
 /// <param name="val">The current value of the property.</param>
 public PropertySpecificationEventArgs(PropertySpecification property, object val)
 {
     this.Property = property;
     this.Value    = val;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertySpecificationDescriptor"/> class.
 /// </summary>
 /// <param name="specification">The specification.</param>
 /// <param name="containingBag">The containing bag.</param>
 /// <param name="propertyAttributes">The property attributes.</param>
 public PropertySpecificationDescriptor(PropertySpecification specification, PropertyBag containingBag, Attribute[] propertyAttributes) :
     base(specification.Name, propertyAttributes)
 {
     ContainingBag = containingBag;
     Specification = specification;
 }