예제 #1
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context)
        {
            if (_values == null)
            {
                CultureInfo?[] installedCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures | CultureTypes.NeutralCultures);
                int            invariantIndex    = Array.IndexOf(installedCultures, CultureInfo.InvariantCulture);

                CultureInfo[] array;
                if (invariantIndex != -1)
                {
                    Debug.Assert(invariantIndex >= 0 && invariantIndex < installedCultures.Length);
                    installedCultures[invariantIndex] = null;
                    array = new CultureInfo[installedCultures.Length];
                }
                else
                {
                    array = new CultureInfo[installedCultures.Length + 1];
                }

                Array.Copy(installedCultures, array, installedCultures.Length);
                Array.Sort(array, new CultureComparer(this));
                Debug.Assert(array[0] == null);
                if (array[0] == null)
                {
                    //we replace null with the real default culture because there are code paths
                    // where the propgrid will send values from this returned array directly -- instead
                    // of converting it to a string and then back to a value (which this relied on).
                    array[0] = CultureInfo.InvariantCulture; //null isn't the value here -- invariantculture is.
                }

                _values = new StandardValuesCollection(array);
            }

            return(_values);
        }
예제 #2
0
 public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context)
 {
     if (s_values == null)
     {
         s_values = new StandardValuesCollection(new object?[] { null });
     }
     return(s_values);
 }
예제 #3
0
        /// <summary>
        ///  Retrieves a collection containing a set of standard values
        ///  for the data type this validator is designed for.  This
        ///  will return null if the data type does not support a
        ///  standard set of values.
        /// </summary>
        public override StandardValuesCollection?GetStandardValues(ITypeDescriptorContext?context)
        {
            if (_values is null)
            {
                object[] objValues = _com2Enum.Values;
                if (objValues is not null)
                {
                    _values = new StandardValuesCollection(objValues);
                }
            }

            return(_values);
        }
예제 #4
0
            public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context)
            {
                if (_values is null)
                {
                    // chose from two GUIDs we pregenerated for testing
                    _values = new StandardValuesCollection(new Guid?[]
                    {
                        null,
                        new Guid("38EA9AE9-13BE-4992-9482-DAD370894BBD"),
                        new Guid("46DFEE70-A89E-4D9A-8842-6D46DBC1F195"),
                    });
                }

                return(_values);
            }
예제 #5
0
        /// <summary>
        ///  Retrieves a collection containing a set of standard values
        ///  for the data type this validator is designed for.  This
        ///  will return null if the data type does not support a
        ///  standard set of values.
        /// </summary>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context)
        {
            if (_values is null)
            {
                ArrayList      list  = new ArrayList();
                PropertyInfo[] props = GetProperties();
                for (int i = 0; i < props.Length; i++)
                {
                    PropertyInfo prop = props[i];
                    object[]? tempIndex = null;
                    Debug.Assert(prop.GetValue(null, tempIndex) is not null, "Property " + prop.Name + " returned NULL");
                    list.Add(prop.GetValue(null, tempIndex));
                }

                _values = new StandardValuesCollection(list.ToArray());
            }

            return(_values);
        }
예제 #6
0
        /// <summary>
        ///  Retrieves a collection containing a set of standard values
        ///  for the data type this validator is designed for.  This
        ///  will return null if the data type does not support a
        ///  standard set of values.
        /// </summary>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context)
        {
            if (_values is null)
            {
                ArrayList list = new ArrayList();

                ICollection <Keys> keys = KeyNames.Values;

                foreach (object o in keys)
                {
                    list.Add(o);
                }

                list.Sort(this);

                _values = new StandardValuesCollection(list.ToArray());
            }

            return(_values);
        }
예제 #7
0
        /// <summary>
        /// Gets a collection of standard values for the data type this validator is designed for.
        /// </summary>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context)
        {
            if (_values == null)
            {
                object[]? objTypes;

                if (_types != null)
                {
                    objTypes = new object[_types.Length];
                    Array.Copy(_types, objTypes, _types.Length);
                }
                else
                {
                    objTypes = null;
                }

                _values = new StandardValuesCollection(objTypes);
            }
            return(_values);
        }
예제 #8
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            lock (creatingCached)
            {
                if (cached != null)
                {
                    return(cached);
                }
                Array colors = Array.CreateInstance(typeof(Color), KnownColors.ArgbValues.Length - 1);
                for (int i = 1; i < KnownColors.ArgbValues.Length; i++)
                {
                    colors.SetValue(KnownColors.FromKnownColor((KnownColor)i), i - 1);
                }

                Array.Sort(colors, 0, colors.Length, new CompareColors());
                cached = new StandardValuesCollection(colors);
            }

            return(cached);
        }
예제 #9
0
        /// <summary>
        /// Gets a collection of standard values for the data type this type converter is designed for.
        /// </summary>
        public override StandardValuesCollection?GetStandardValues(ITypeDescriptorContext?context)
        {
            if (UnderlyingTypeConverter != null)
            {
                StandardValuesCollection?values = UnderlyingTypeConverter.GetStandardValues(context);
                if (GetStandardValuesSupported(context) && values != null)
                {
                    // Create a set of standard values around nullable instances.
                    object?[] wrappedValues = new object[values.Count + 1];
                    int       idx           = 0;

                    wrappedValues[idx++] = null;
                    foreach (object value in values)
                    {
                        wrappedValues[idx++] = value;
                    }

                    return(new StandardValuesCollection(wrappedValues));
                }
            }

            return(base.GetStandardValues(context));
        }
예제 #10
0
        /// <summary>
        /// Gets a collection of standard values for the data type this validator is
        /// designed for.
        /// </summary>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context)
        {
            if (Values == null)
            {
                // We need to get the enum values in this rather round-about way so we can filter
                // out fields marked Browsable(false). Note that if multiple fields have the same value,
                // the behavior is undefined, since what we return are just enum values, not names.
                Type reflectType = TypeDescriptor.GetReflectionType(EnumType) ?? EnumType;

                FieldInfo[]? fields = reflectType.GetFields(BindingFlags.Public | BindingFlags.Static);
                ArrayList?objValues = null;

                if (fields != null && fields.Length > 0)
                {
                    objValues = new ArrayList(fields.Length);
                }

                if (objValues != null)
                {
                    foreach (FieldInfo field in fields !)
                    {
                        BrowsableAttribute?browsableAttr = null;
                        foreach (Attribute attr in field.GetCustomAttributes(typeof(BrowsableAttribute), false))
                        {
                            browsableAttr = attr as BrowsableAttribute;
                        }

                        if (browsableAttr == null || browsableAttr.Browsable)
                        {
                            object?value = null;

                            try
                            {
                                if (field.Name != null)
                                {
                                    value = Enum.Parse(EnumType, field.Name);
                                }
                            }
                            catch (ArgumentException)
                            {
                                // Hmm, for some reason, the parse threw. Let us ignore this value.
                            }

                            if (value != null)
                            {
                                objValues.Add(value);
                            }
                        }
                    }

                    IComparer?comparer = Comparer;
                    if (comparer != null)
                    {
                        objValues.Sort(comparer);
                    }
                }

                Array?arr = objValues?.ToArray();
                Values = new StandardValuesCollection(arr);
            }
            return(Values);
        }
예제 #11
0
 public void RefreshValues()
 {
     _values = null;
 }
예제 #12
0
 /// <summary>
 /// Gets a collection of standard values for the Boolean data type.
 /// </summary>
 public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context)
 {
     return(s_values ?? (s_values = new StandardValuesCollection(new object[] { true, false })));
 }