System.ComponentModel.ReflectPropertyDescriptor.ReflectPropertyDescriptor C# (CSharp) Method

ReflectPropertyDescriptor() public method

This constructor takes an existing ReflectPropertyDescriptor and modifies it by merging in the passed-in attributes.
public ReflectPropertyDescriptor ( Type componentClass, PropertyDescriptor oldReflectPropertyDescriptor, Attribute attributes ) : System.Collections
componentClass Type
oldReflectPropertyDescriptor PropertyDescriptor
attributes Attribute
return System.Collections
        public ReflectPropertyDescriptor(Type componentClass, PropertyDescriptor oldReflectPropertyDescriptor, Attribute[] attributes)
        : base(oldReflectPropertyDescriptor, attributes)
        {
            _componentClass = componentClass;
            _type = oldReflectPropertyDescriptor.PropertyType;

            if (componentClass == null)
            {
                throw new ArgumentException(string.Format(SR.InvalidNullArgument, nameof(componentClass)));
            }

            // If the classes are the same, we can potentially optimize the method fetch because
            // the old property descriptor may already have it.
            //
            ReflectPropertyDescriptor oldProp = oldReflectPropertyDescriptor as ReflectPropertyDescriptor;
            if (oldProp != null)
            {
                if (oldProp.ComponentType == componentClass)
                {
                    _propInfo = oldProp._propInfo;
                    _getMethod = oldProp._getMethod;
                    _setMethod = oldProp._setMethod;
                    _shouldSerializeMethod = oldProp._shouldSerializeMethod;
                    _resetMethod = oldProp._resetMethod;
                    _defaultValue = oldProp._defaultValue;
                    _ambientValue = oldProp._ambientValue;
                    _state = oldProp._state;
                }

                // Now we must figure out what to do with our default value.  First, check to see
                // if the caller has provided an new default value attribute.  If so, use it.  Otherwise,
                // just let it be and it will be picked up on demand.
                //
                if (attributes != null)
                {
                    foreach (Attribute a in attributes)
                    {
                        DefaultValueAttribute dva = a as DefaultValueAttribute;

                        if (dva != null)
                        {
                            _defaultValue = dva.Value;
                            // Default values for enums are often stored as their underlying integer type:
                            if (_defaultValue != null && PropertyType.GetTypeInfo().IsEnum && PropertyType.GetTypeInfo().GetEnumUnderlyingType() == _defaultValue.GetType())
                            {
                                _defaultValue = Enum.ToObject(PropertyType, _defaultValue);
                            }

                            _state.DangerousSet(s_bitDefaultValueQueried, true);
                        }
                        else
                        {
                            AmbientValueAttribute ava = a as AmbientValueAttribute;
                            if (ava != null)
                            {
                                _ambientValue = ava.Value;
                                _state.DangerousSet(s_bitAmbientValueQueried, true);
                            }
                        }
                    }
                }
            }
        }

Same methods

ReflectPropertyDescriptor::ReflectPropertyDescriptor ( Type componentClass, string name, Type type, Attribute attributes ) : System.Collections
ReflectPropertyDescriptor::ReflectPropertyDescriptor ( Type componentClass, string name, Type type, PropertyInfo propInfo, MethodInfo getMethod, MethodInfo setMethod, Attribute attrs ) : System.Collections
ReflectPropertyDescriptor::ReflectPropertyDescriptor ( Type componentClass, string name, Type type, Type receiverType, MethodInfo getMethod, MethodInfo setMethod, Attribute attrs ) : System.Collections