コード例 #1
0
        public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
        {
            if (propertyValues == null)
            {
                throw new ArgumentNullException(nameof(propertyValues));
            }

            object obj1 = propertyValues[(object)"Color1"];
            object obj2 = propertyValues[(object)"Color2"];
            object obj3 = propertyValues[(object)"Style"];
            object obj4 = propertyValues[(object)"GammaCorrection"];

            var defalt = new GradientBrush(GetHost(context));

            if (obj1 == null)
            {
                obj1 = defalt.Color1;
            }
            if (obj2 == null)
            {
                obj2 = defalt.Color2;
            }
            if (obj3 == null)
            {
                obj3 = defalt.Style;
            }
            if (obj4 == null)
            {
                obj4 = defalt.GammaCorrection;
            }

            if (!(obj1 is Color) || !(obj2 is Color) || !(obj3 is GradientStyle) || !(obj4 is bool))
            {
                throw new ArgumentException("One or more entries are not valid in the IDictionary parameter. Verify that all values match up to the object's properties.");
            }

            return((object)new GradientBrush(GetHost(context), (Color)obj1, (Color)obj2, (GradientStyle)obj3, (bool)obj4));
        }