Ejemplo n.º 1
0
        /// <summary>
        /// Obtains the <see cref="TypeConverter.StandardValuesCollection"/> from <see cref="EnumConverter.GetStandardValues"/>,
        /// and adds the current value to the beginning of the <see cref="TypeConverter.StandardValuesCollection"/>, if necessary.
        /// </summary>
        /// <remarks>
        /// The current value will be added to the beginning of the <see cref="TypeConverter.StandardValuesCollection"/> returned
        /// by <see cref="EnumConverter.GetStandardValues"/> if the following conditions are met:
        /// <list type="bullet">
        /// <item><description><paramref name="context"/> is not <see langword="null"/></description></item>
        /// <item><description><see cref="ITypeDescriptorContext.Instance"/> is not <see langword="null"/>.</description></item>
        /// <item><description><see cref="ITypeDescriptorContext.PropertyDescriptor"/> is not <see langword="null"/>.</description></item>
        /// <item><description><see cref="PropertyDescriptor.GetValue"/> returns a value of type <typeparamref name="TEnum"/>.</description></item>
        /// <item><description><see cref="Enum.IsDefined"/> returns <see langword="true"/> for that value.</description></item>
        /// <item><description>The <see cref="TypeConverter.StandardValuesCollection"/> returned by <see cref="EnumConverter.GetStandardValues"/> does not already contain that value.</description></item>
        /// </list>
        /// </remarks>
        /// <seealso cref="TypeConverter.GetStandardValues(ITypeDescriptorContext)"/>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            StandardValuesCollection standardValuesCollection = base.GetStandardValues(context);
            object             component;
            PropertyDescriptor propertyDescriptor;

            if (context != null && (component = context.Instance) != null && (propertyDescriptor = context.PropertyDescriptor) != null)
            {
                TEnum?        valueNullable = propertyDescriptor.GetValue(component) as TEnum?;
                TEnum         value;
                EnumValueInfo?valueInfoNullable;
                if (valueNullable.HasValue && (valueInfoNullable = GetValueInfo(value = valueNullable.Value)).HasValue)
                {
                    // Since we found an EnumValueInfo for the value, we know that Enum.IsDefined would return true
                    if (!valueInfoNullable.Value.Browsable)
                    {
                        // Since the value is not browsable, it will not be in the StandardValuesCollection we retrieved from EnumConverter,
                        // so we have to add it.
                        TEnum[] newStandardValues = new TEnum[standardValuesCollection.Count + 1];
                        newStandardValues[0] = value;
                        standardValuesCollection.CopyTo(newStandardValues, 1);
                        return(new StandardValuesCollection(newStandardValues));
                    }
                }
            }
            return(standardValuesCollection);
        }
Ejemplo n.º 2
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            StandardValuesCollection stdv = base.GetStandardValues(context);

            AutoCompleteSource[] arr = new AutoCompleteSource[stdv.Count];
            stdv.CopyTo(arr, 0);
            AutoCompleteSource[] arr2 = Array.FindAll(arr, delegate(AutoCompleteSource value) {
                // No "ListItems" in a TextBox.
                return(value != AutoCompleteSource.ListItems);
            });
            return(new StandardValuesCollection(arr2));
        }