internal DynamicProperty(DynamicTypeDescriptor descriptor, Type type, object value, string name, Attribute[] attrs)
                : base(name, attrs)
            {
                _descriptor = descriptor;
                _type       = type;
                Value       = value;
                DefaultValueAttribute def = DynamicTypeDescriptor.GetAttribute <DefaultValueAttribute>(Attributes);

                if (def == null)
                {
                    _hasDefaultValue = false;
                }
                else
                {
                    _hasDefaultValue = true;
                    _defaultValue    = def.Value;
                }
                if (attrs != null)
                {
                    foreach (Attribute att in attrs)
                    {
                        _attributes.Add(att);
                    }
                }
            }
        public DynamicTypeDescriptor FromComponent(object component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            if (!_type.IsAssignableFrom(component.GetType()))
            {
                throw new ArgumentException(null, "component");
            }

            DynamicTypeDescriptor desc = new DynamicTypeDescriptor();

            desc._type     = _type;
            desc.Component = component;

            // shallow copy on purpose
            desc._typeConverter     = _typeConverter;
            desc._editors           = _editors;
            desc._defaultEvent      = _defaultEvent;
            desc._defaultProperty   = _defaultProperty;
            desc._attributes        = _attributes;
            desc._events            = _events;
            desc.OriginalProperties = OriginalProperties;

            // track values
            List <PropertyDescriptor> properties = new List <PropertyDescriptor>();

            foreach (PropertyDescriptor pd in Properties)
            {
                DynamicProperty ap = new DynamicProperty(desc, pd, component);
                properties.Add(ap);
            }

            desc.Properties = new PropertyDescriptorCollection(properties.ToArray());
            return(desc);
        }
 internal DynamicProperty(DynamicTypeDescriptor descriptor, PropertyDescriptor existing, object component)
     : this(descriptor, existing.PropertyType, existing.GetValue(component), existing.Name, GetAttributes(existing))
 {
     _existing = existing;
 }