Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref='System.ComponentModel.Design.ComponentDesigner' /> class using the specified component.
        /// </summary>
        public virtual void Initialize(IComponent component)
        {
            Debug.Assert(component != null, "Can't create designer with no component!");

            _component = component;

            // For inherited components, save off the current values so we can compute a delta.  We also do this for the root component, but,
            // as it is ALWAYS inherited, the computation of default values favors the presence of a default value attribute over the current code value.
            bool          isRoot = false;
            IDesignerHost host   = (IDesignerHost)GetService(typeof(IDesignerHost));

            if (host != null && component == host.RootComponent)
            {
                isRoot = true;
            }

            if (component.Site is IServiceContainer sc && GetService(typeof(DesignerCommandSet)) == null)
            {
                sc.AddService(typeof(DesignerCommandSet), new CDDesignerCommandSet(this));
            }

            IComponentChangeService cs = (IComponentChangeService)GetService(typeof(IComponentChangeService));

            if (cs != null)
            {
                cs.ComponentRename += new ComponentRenameEventHandler(OnComponentRename);
            }

            if (isRoot || !InheritanceAttribute.Equals(InheritanceAttribute.NotInherited))
            {
                InitializeInheritedProperties(isRoot);
            }
        }
        /// <include file='doc\ComponentDesigner.uex' path='docs/doc[@for="ComponentDesigner.Initialize"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Initializes a new instance of the <see cref='System.ComponentModel.Design.ComponentDesigner'/>
        ///       class using the specified component.
        ///    </para>
        /// </devdoc>
        public virtual void Initialize(IComponent component)
        {
            Debug.Assert(component != null, "Can't create designer with no component!");

            this.component = component;

            // For inherited components, save off the current values so we can
            // compute a delta.  We also do this for the root component, but,
            // as it is ALWAYS inherited, the computation of default values
            // favors the presence of a default value attribute over
            // the current code value.
            //
            bool          isRoot = false;
            IDesignerHost host   = (IDesignerHost)GetService(typeof(IDesignerHost));

            if (host != null && component == host.RootComponent)
            {
                isRoot = true;
            }

            if (isRoot || !InheritanceAttribute.Equals(InheritanceAttribute.NotInherited))
            {
                InitializeInheritedProperties(isRoot);
            }
        }
        /// <summary>
        ///  We don't actually want to serialize any code here, so we just delegate that to the base type's
        ///  serializer. All we want to do is if we are in a localizable form, we want to push a
        ///  'LayoutSettings' entry into the resx.
        /// </summary>
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            // First call the base serializer to serialize the object.
            object codeObject = GetBaseSerializer(manager).Serialize(manager, value);

            // Now push our layout settings stuff into the resx if we are not inherited read only and
            // are in a localizable Form.
            TableLayoutPanel tlp = value as TableLayoutPanel;

            Debug.Assert(tlp != null, "Huh? We were expecting to be serializing a TableLayoutPanel here.");

            if (tlp != null)
            {
                InheritanceAttribute ia = (InheritanceAttribute)TypeDescriptor.GetAttributes(tlp)[typeof(InheritanceAttribute)];

                if (ia is null || ia.InheritanceLevel != InheritanceLevel.InheritedReadOnly)
                {
                    IDesignerHost host = (IDesignerHost)manager.GetService(typeof(IDesignerHost));

                    if (IsLocalizable(host))
                    {
                        PropertyDescriptor lsProp = TypeDescriptor.GetProperties(tlp)[LayoutSettingsPropName];
                        object             val    = (lsProp != null) ? lsProp.GetValue(tlp) : null;

                        if (val != null)
                        {
                            string key = manager.GetName(tlp) + "." + LayoutSettingsPropName;
                            SerializeResourceInvariant(manager, key, val);
                        }
                    }
                }
            }

            return(codeObject);
        }
Exemplo n.º 4
0
        /// <summary>
        ///  Allows a designer to filter the set of events the component it is designing will expose through the TypeDescriptor object.
        /// </summary>
        protected virtual void PostFilterEvents(IDictionary events)
        {
            // If this component is being privately inherited, we need to filter the events to make them read-only.
            if (events is null)
            {
                return;
            }

            InheritanceAttribute inheritanceAttribute = InheritanceAttribute;

            if (inheritanceAttribute is null || !inheritanceAttribute.Equals(InheritanceAttribute.InheritedReadOnly))
            {
                return;
            }

            EventDescriptor[] values = new EventDescriptor[events.Values.Count];
            events.Values.CopyTo(values, 0);

            for (int i = 0; i < values.Length; i++)
            {
                EventDescriptor evt = values[i];
                if (evt != null)
                {
                    events[evt.Name] = TypeDescriptor.CreateEvent(evt.ComponentType, evt, ReadOnlyAttribute.Yes);
                }
            }
        }
Exemplo n.º 5
0
        public void Ctor_Default()
        {
            var attribute = new InheritanceAttribute();

            Assert.Equal(InheritanceLevel.NotInherited, attribute.InheritanceLevel);
            Assert.True(attribute.IsDefaultAttribute());
        }
Exemplo n.º 6
0
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            object           obj2      = this.GetBaseSerializer(manager).Serialize(manager, value);
            TableLayoutPanel component = value as TableLayoutPanel;

            if (component != null)
            {
                InheritanceAttribute attribute = (InheritanceAttribute)TypeDescriptor.GetAttributes(component)[typeof(InheritanceAttribute)];
                if ((attribute == null) || (attribute.InheritanceLevel != InheritanceLevel.InheritedReadOnly))
                {
                    IDesignerHost service = (IDesignerHost)manager.GetService(typeof(IDesignerHost));
                    if (this.IsLocalizable(service))
                    {
                        PropertyDescriptor descriptor = TypeDescriptor.GetProperties(component)[LayoutSettingsPropName];
                        object             obj3       = (descriptor != null) ? descriptor.GetValue(component) : null;
                        if (obj3 != null)
                        {
                            string resourceName = manager.GetName(component) + "." + LayoutSettingsPropName;
                            base.SerializeResourceInvariant(manager, resourceName, obj3);
                        }
                    }
                }
            }
            return(obj2);
        }
Exemplo n.º 7
0
        public void Ctor_InheritanceLevel(InheritanceLevel inheritanceLevel)
        {
            var attribute = new InheritanceAttribute(inheritanceLevel);

            Assert.Equal(inheritanceLevel, attribute.InheritanceLevel);
            Assert.Equal(inheritanceLevel == InheritanceLevel.NotInherited, attribute.IsDefaultAttribute());
        }
Exemplo n.º 8
0
        private static bool HasMixedInheritedChildren(Control parent)
        {
            bool inheritedChildren    = false;
            bool nonInheritedChildren = false;

            foreach (Control c in parent.Controls)
            {
                InheritanceAttribute ia = (InheritanceAttribute)TypeDescriptor.GetAttributes(c)[typeof(InheritanceAttribute)];

                if (ia != null && ia.InheritanceLevel != InheritanceLevel.NotInherited)
                {
                    inheritedChildren = true;
                }
                else
                {
                    nonInheritedChildren = true;
                }

                if (inheritedChildren && nonInheritedChildren)
                {
                    return(true);
                }
            }

            return(false);
        }
        protected override bool HasSitedNonReadonlyChildren(Control parent)
        {
            ToolStrip toolStrip = parent as ToolStrip;

            if (toolStrip is null)
            {
                Debug.Fail("why were we passed a non winbar?");
                return(false);
            }

            if (toolStrip.Items.Count == 0)
            {
                return(false);
            }

            foreach (ToolStripItem item in toolStrip.Items)
            {
                if (item.Site != null && toolStrip.Site != null && item.Site.Container == toolStrip.Site.Container)
                {
                    // We only emit Size/Location information for controls that are sited and not inherrited readonly.
                    InheritanceAttribute ia = (InheritanceAttribute)TypeDescriptor.GetAttributes(item)[typeof(InheritanceAttribute)];

                    if (ia != null && ia.InheritanceLevel != InheritanceLevel.InheritedReadOnly)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 10
0
 private void SerializeZOrder(IDesignerSerializationManager manager, CodeStatementCollection statements, Control control)
 {
     using (CodeDomSerializerBase.TraceScope("ControlCodeDomSerializer::SerializeZOrder()"))
     {
         for (int i = control.Controls.Count - 1; i >= 0; i--)
         {
             Control component = control.Controls[i];
             if ((component.Site != null) && (component.Site.Container == control.Site.Container))
             {
                 InheritanceAttribute attribute = (InheritanceAttribute)TypeDescriptor.GetAttributes(component)[typeof(InheritanceAttribute)];
                 if (attribute.InheritanceLevel != InheritanceLevel.InheritedReadOnly)
                 {
                     CodeExpression targetObject = new CodePropertyReferenceExpression(base.SerializeToExpression(manager, control), "Controls");
                     CodeMethodReferenceExpression expression2 = new CodeMethodReferenceExpression(targetObject, "SetChildIndex");
                     CodeMethodInvokeExpression    expression  = new CodeMethodInvokeExpression {
                         Method = expression2
                     };
                     CodeExpression expression4 = base.SerializeToExpression(manager, component);
                     expression.Parameters.Add(expression4);
                     expression.Parameters.Add(base.SerializeToExpression(manager, 0));
                     CodeExpressionStatement statement = new CodeExpressionStatement(expression);
                     statements.Add(statement);
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        ///  Initializes a new instance of the <see cref="ComponentDesigner"/> class using the specified component.
        /// </summary>
        public virtual void Initialize(IComponent component)
        {
            Component = component;

            // For inherited components, save off the current values so we can compute a delta.  We also do this for
            // the root component, but, as it is ALWAYS inherited, the computation of default values favors the
            // presence of a default value attribute over the current code value.
            bool isRoot = TryGetService(out IDesignerHost host) && component == host.RootComponent;

            if (component?.Site is IServiceContainer sc && GetService(typeof(DesignerCommandSet)) is null)
            {
                sc.AddService(typeof(DesignerCommandSet), new CDDesignerCommandSet(this));
            }

            if (TryGetService(out IComponentChangeService cs))
            {
                cs.ComponentRename += new ComponentRenameEventHandler(OnComponentRename);
            }

            InheritanceAttribute inheritanceAttribute = InheritanceAttribute;

            if (isRoot || InheritanceAttribute is null || !inheritanceAttribute.Equals(InheritanceAttribute.NotInherited))
            {
                InitializeInheritedProperties();
            }
        }
Exemplo n.º 12
0
 public void Equals_Object_ReturnsExpected(InheritanceAttribute attribute, object other, bool expected)
 {
     Assert.Equal(expected, attribute.Equals(other));
     if (other is InheritanceAttribute)
     {
         Assert.Equal(expected, attribute.GetHashCode().Equals(other.GetHashCode()));
     }
 }
Exemplo n.º 13
0
        public void NotInherited_Get_ReturnsExpected()
        {
            InheritanceAttribute attribute = InheritanceAttribute.NotInherited;

            Assert.Same(attribute, InheritanceAttribute.NotInherited);

            Assert.Equal(InheritanceLevel.NotInherited, attribute.InheritanceLevel);
            Assert.True(attribute.IsDefaultAttribute());
        }
Exemplo n.º 14
0
        public void InheritedReadOnly_Get_ReturnsExpected()
        {
            InheritanceAttribute attribute = InheritanceAttribute.InheritedReadOnly;

            Assert.Same(attribute, InheritanceAttribute.InheritedReadOnly);

            Assert.Equal(InheritanceLevel.InheritedReadOnly, attribute.InheritanceLevel);
            Assert.False(attribute.IsDefaultAttribute());
        }
Exemplo n.º 15
0
 /// <include file='doc\ComponentDesigner.uex' path='docs/doc[@for="ComponentDesigner.PostFilterAttributes"]/*' />
 /// <devdoc>
 ///    <para>
 ///       Allows a
 ///       designer to filter the set of member attributes the
 ///       component it is designing will expose through the
 ///       TypeDescriptor object.
 ///    </para>
 /// </devdoc>
 protected virtual void PostFilterAttributes(IDictionary attributes)
 {
     // If this component is being inherited, mark it as such in the class attributes.
     //
     if (!InheritanceAttribute.Equals(InheritanceAttribute.NotInherited))
     {
         attributes[typeof(InheritanceAttribute)] = InheritanceAttribute;
     }
 }
Exemplo n.º 16
0
        /// <summary>
        ///  Gets the inheritance attribute of the specified component.
        /// </summary>
        public InheritanceAttribute GetInheritanceAttribute(IComponent component)
        {
            InheritanceAttribute attr = (InheritanceAttribute)_inheritedComponents[component];

            if (attr == null)
            {
                attr = InheritanceAttribute.Default;
            }
            return(attr);
        }
        static bool IsInherited(object component)
        {
            InheritanceAttribute attribute = GetInheritanceAttribute(component);

            if (attribute != null)
            {
                return(attribute.InheritanceLevel != InheritanceLevel.NotInherited);
            }
            return(false);
        }
        internal DesignerActionGlyph GetDesignerActionGlyph(IComponent comp, DesignerActionListCollection dalColl)
        {
            InheritanceAttribute attribute = (InheritanceAttribute)TypeDescriptor.GetAttributes(comp)[typeof(InheritanceAttribute)];

            if (attribute != InheritanceAttribute.InheritedReadOnly)
            {
                if (dalColl == null)
                {
                    dalColl = this.designerActionService.GetComponentActions(comp);
                }
                if ((dalColl != null) && (dalColl.Count > 0))
                {
                    DesignerActionGlyph glyph = null;
                    if (this.componentToGlyph[comp] == null)
                    {
                        DesignerActionBehavior behavior = new DesignerActionBehavior(this.serviceProvider, comp, dalColl, this);
                        if (!(comp is Control) || (comp is ToolStripDropDown))
                        {
                            ComponentTray service = this.serviceProvider.GetService(typeof(ComponentTray)) as ComponentTray;
                            if (service != null)
                            {
                                ComponentTray.TrayControl trayControlFromComponent = service.GetTrayControlFromComponent(comp);
                                if (trayControlFromComponent != null)
                                {
                                    Rectangle bounds = trayControlFromComponent.Bounds;
                                    glyph = new DesignerActionGlyph(behavior, bounds, service);
                                }
                            }
                        }
                        if (glyph == null)
                        {
                            glyph = new DesignerActionGlyph(behavior, this.designerActionAdorner);
                        }
                        if (glyph != null)
                        {
                            this.componentToGlyph.Add(comp, glyph);
                        }
                        return(glyph);
                    }
                    glyph = this.componentToGlyph[comp] as DesignerActionGlyph;
                    if (glyph != null)
                    {
                        DesignerActionBehavior behavior2 = glyph.Behavior as DesignerActionBehavior;
                        if (behavior2 != null)
                        {
                            behavior2.ActionLists = dalColl;
                        }
                        glyph.Invalidate();
                    }
                    return(glyph);
                }
                this.RemoveActionGlyph(comp);
            }
            return(null);
        }
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            if (manager == null || value == null)
            {
                throw new ArgumentNullException((manager == null) ? "manager" : "value");
            }
            CodeDomSerializer codeDomSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(Component), typeof(CodeDomSerializer));

            if (codeDomSerializer == null)
            {
                return(null);
            }
            object obj = codeDomSerializer.Serialize(manager, value);
            InheritanceAttribute inheritanceAttribute = (InheritanceAttribute)TypeDescriptor.GetAttributes(value)[typeof(InheritanceAttribute)];
            InheritanceLevel     inheritanceLevel     = InheritanceLevel.NotInherited;

            if (inheritanceAttribute != null)
            {
                inheritanceLevel = inheritanceAttribute.InheritanceLevel;
            }
            if (inheritanceLevel != InheritanceLevel.InheritedReadOnly)
            {
                IDesignerHost designerHost = (IDesignerHost)manager.GetService(typeof(IDesignerHost));
                if (designerHost != null)
                {
                    PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(designerHost.RootComponent)["Localizable"];
                    if (propertyDescriptor != null && propertyDescriptor.PropertyType == typeof(bool) && (bool)propertyDescriptor.GetValue(designerHost.RootComponent))
                    {
                        this.SerializeControlHierarchy(manager, designerHost, value);
                    }
                }
                CodeStatementCollection codeStatementCollection = obj as CodeStatementCollection;
                if (codeStatementCollection != null)
                {
                    Control control = (Control)value;
                    if ((designerHost != null && control == designerHost.RootComponent) || this.HasSitedNonReadonlyChildren(control))
                    {
                        this.SerializeSuspendLayout(manager, codeStatementCollection, value);
                        this.SerializeResumeLayout(manager, codeStatementCollection, value);
                        ControlDesigner controlDesigner            = designerHost.GetDesigner(control) as ControlDesigner;
                        var             serializePerformLayoutProp = typeof(ControlDesigner).GetProperty("SerializePerformLayout", BindingFlags.NonPublic | BindingFlags.Instance);

                        if (this.HasAutoSizedChildren(control) || (controlDesigner != null && (bool)serializePerformLayoutProp.GetValue(controlDesigner)))
                        {
                            this.SerializePerformLayout(manager, codeStatementCollection, value);
                        }
                    }
                    if (this.HasMixedInheritedChildren(control))
                    {
                        this.SerializeZOrder(manager, codeStatementCollection, control);
                    }
                }
            }
            return(obj);
        }
Exemplo n.º 20
0
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            if ((manager == null) || (value == null))
            {
                throw new ArgumentNullException((manager == null) ? "manager" : "value");
            }
            CodeDomSerializer serializer = (CodeDomSerializer)manager.GetSerializer(typeof(Component), typeof(CodeDomSerializer));

            if (serializer == null)
            {
                return(null);
            }
            object obj2 = serializer.Serialize(manager, value);
            InheritanceAttribute attribute    = (InheritanceAttribute)TypeDescriptor.GetAttributes(value)[typeof(InheritanceAttribute)];
            InheritanceLevel     notInherited = InheritanceLevel.NotInherited;

            if (attribute != null)
            {
                notInherited = attribute.InheritanceLevel;
            }
            if (notInherited != InheritanceLevel.InheritedReadOnly)
            {
                IDesignerHost service = (IDesignerHost)manager.GetService(typeof(IDesignerHost));
                if (service != null)
                {
                    PropertyDescriptor descriptor = TypeDescriptor.GetProperties(service.RootComponent)["Localizable"];
                    if (((descriptor != null) && (descriptor.PropertyType == typeof(bool))) && ((bool)descriptor.GetValue(service.RootComponent)))
                    {
                        this.SerializeControlHierarchy(manager, service, value);
                    }
                }
                CodeStatementCollection statements = obj2 as CodeStatementCollection;
                if (statements == null)
                {
                    return(obj2);
                }
                Control parent = (Control)value;
                if (((service != null) && (parent == service.RootComponent)) || this.HasSitedNonReadonlyChildren(parent))
                {
                    this.SerializeSuspendLayout(manager, statements, value);
                    this.SerializeResumeLayout(manager, statements, value);
                    ControlDesigner designer = service.GetDesigner(parent) as ControlDesigner;
                    if (this.HasAutoSizedChildren(parent) || ((designer != null) && designer.SerializePerformLayout))
                    {
                        this.SerializePerformLayout(manager, statements, value);
                    }
                }
                if (this.HasMixedInheritedChildren(parent))
                {
                    this.SerializeZOrder(manager, statements, parent);
                }
            }
            return(obj2);
        }
Exemplo n.º 21
0
        /// <summary>
        ///  This method returns true if the given member descriptor should be serialized,
        ///  or false if there is no need to serialize the member.
        /// </summary>
        public override bool ShouldSerialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor)
        {
            bool shouldSerialize = _serializer.ShouldSerialize(manager, value, descriptor);

            if (!shouldSerialize && !descriptor.Attributes.Contains(DesignOnlyAttribute.Yes))
            {
                switch (_model)
                {
                case CodeDomLocalizationModel.PropertyReflection:
                    if (!shouldSerialize)
                    {
                        // hook up the event the first time to clear out our cache at the end of the serialization
                        if (localizationLanguage is null)
                        {
                            manager.SerializationComplete += new EventHandler(OnSerializationComplete);
                        }

                        if (GetLocalizationLanguage(manager) != CultureInfo.InvariantCulture)
                        {
                            shouldSerialize = true;
                        }
                    }

                    break;

                case CodeDomLocalizationModel.PropertyAssignment:
                    // If this property contains its default value, we still want to serialize it if we are in
                    // localization mode if we are writing to the default culture, but only if the object
                    // is not inherited.
                    InheritanceAttribute inheritance = (InheritanceAttribute)manager.Context[typeof(InheritanceAttribute)];

                    if (inheritance is null)
                    {
                        inheritance = (InheritanceAttribute)TypeDescriptor.GetAttributes(value)[typeof(InheritanceAttribute)];
                        if (inheritance is null)
                        {
                            inheritance = InheritanceAttribute.NotInherited;
                        }
                    }

                    if (inheritance.InheritanceLevel != InheritanceLevel.InheritedReadOnly)
                    {
                        shouldSerialize = true;
                    }

                    break;

                default:
                    break;
                }
            }

            return(shouldSerialize);
        }
Exemplo n.º 22
0
 void IDesignerFilter.PostFilterAttributes(IDictionary attributes)
 {
     // If this component is being inherited, mark it as such in the class attributes.
     if (attributes.Contains(typeof(InheritanceAttribute)))
     {
         _inheritanceAttribute = attributes[typeof(InheritanceAttribute)] as InheritanceAttribute;
     }
     else if (!InheritanceAttribute.Equals(InheritanceAttribute.NotInherited))
     {
         attributes[typeof(InheritanceAttribute)] = InheritanceAttribute;
     }
 }
Exemplo n.º 23
0
 /// <summary>
 /// Allows a designer to filter the set of member attributes the component it is designing will expose through the TypeDescriptor object.
 /// </summary>
 protected virtual void PostFilterAttributes(IDictionary attributes)
 {
     // If this component is being inherited, mark it as such in the class attributes.
     // Also, set our member variable to ensure that what you get by querying through the TypeDescriptor and through InheritanceAttribute directly is the same.
     if (attributes.Contains(typeof(InheritanceAttribute)))
     {
         _inheritanceAttribute = attributes[typeof(InheritanceAttribute)] as InheritanceAttribute;
     }
     else if (!InheritanceAttribute.Equals(InheritanceAttribute.NotInherited))
     {
         attributes[typeof(InheritanceAttribute)] = InheritanceAttribute;
     }
 }
Exemplo n.º 24
0
        // Determine if two objects are equal.
        public override bool Equals(Object value)
        {
            InheritanceAttribute other = (value as InheritanceAttribute);

            if (other != null)
            {
                return(level == other.level);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 25
0
        /// <include file='doc\ComponentDesigner.uex' path='docs/doc[@for="ComponentDesigner.PostFilterProperties"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Allows
        ///       a designer to filter the set of properties the
        ///       component it is designing will expose through the
        ///       TypeDescriptor object.
        ///    </para>
        /// </devdoc>
        protected virtual void PostFilterProperties(IDictionary properties)
        {
            // Check for inheritance
            //
            if (inheritedProps != null)
            {
                bool readOnlyInherit = (InheritanceAttribute.Equals(InheritanceAttribute.InheritedReadOnly));

                if (readOnlyInherit)
                {
                    // Now loop through all the properties.  For each one, try to match a pre-created property.
                    // If that fails, then create a new property.
                    //
                    PropertyDescriptor[] values = new PropertyDescriptor[properties.Values.Count];
                    properties.Values.CopyTo(values, 0);

                    for (int i = 0; i < values.Length; i++)
                    {
                        PropertyDescriptor prop = values[i];
                        // This is a private component.  Therefore, the user should not be
                        // allowed to modify any properties.  We replace all properties with
                        // read-only versions.
                        //
                        properties[prop.Name] = TypeDescriptor.CreateProperty(prop.ComponentType, prop, ReadOnlyAttribute.Yes);
                    }
                }
                else
                {
                    // otherwise apply our inherited properties to the actual property list.
                    //
                    foreach (DictionaryEntry de in inheritedProps)
                    {
                        InheritedPropertyDescriptor inheritedPropDesc = de.Value as InheritedPropertyDescriptor;

                        if (inheritedPropDesc != null)
                        {
                            // replace the property descriptor it was created
                            // with with the new one in case we're shadowing
                            //
                            PropertyDescriptor newInnerProp = (PropertyDescriptor)properties[de.Key];
                            if (newInnerProp != null)
                            {
                                inheritedPropDesc.PropertyDescriptor = newInnerProp;
                                properties[de.Key] = inheritedPropDesc;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 26
0
 void IDesignerFilter.PostFilterAttributes(IDictionary attributes)
 {
     // If this component is being inherited, mark it as such in the class attributes.
     // VSWhidbey #424845 - if the InheritanceAttribute is set in attributes, then don't override it
     // Also, set our member variable to ensure that what you get by querying through the TypeDescriptor and through InheritanceAttribute directly is the same.
     if (attributes.Contains(typeof(InheritanceAttribute)))
     {
         _inheritanceAttribute = attributes[typeof(InheritanceAttribute)] as InheritanceAttribute;
     }
     else if (!InheritanceAttribute.Equals(InheritanceAttribute.NotInherited))
     {
         attributes[typeof(InheritanceAttribute)] = InheritanceAttribute;
     }
 }
Exemplo n.º 27
0
        public static IEnumerable <object[]> Equals_TestData()
        {
            var attribute = new InheritanceAttribute(InheritanceLevel.Inherited);

            yield return(new object[] { attribute, attribute, true });

            yield return(new object[] { attribute, new InheritanceAttribute(InheritanceLevel.Inherited), true });

            yield return(new object[] { attribute, new InheritanceAttribute(InheritanceLevel.InheritedReadOnly), false });

            yield return(new object[] { attribute, new object(), false });

            yield return(new object[] { attribute, null, false });
        }
Exemplo n.º 28
0
        void IDesignerFilter.PostFilterEvents(IDictionary events)
        {
            // If this component is being privately inherited, we need to filter the events to make them read-only.
            if (InheritanceAttribute.Equals(InheritanceAttribute.InheritedReadOnly))
            {
                EventDescriptor[] values = new EventDescriptor[events.Values.Count];
                events.Values.CopyTo(values, 0);

                for (int i = 0; i < values.Length; i++)
                {
                    EventDescriptor evt = values[i];
                    events[evt.Name] = TypeDescriptor.CreateEvent(evt.ComponentType, evt, ReadOnlyAttribute.Yes);
                }
            }
        }
Exemplo n.º 29
0
        private void InitializeInheritedProperties(bool rootComponent)
        {
            Hashtable props = new Hashtable();

            bool readOnlyInherit = (InheritanceAttribute.Equals(InheritanceAttribute.InheritedReadOnly));

            if (!readOnlyInherit)
            {
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(Component);

                // Now loop through all the properties.  For each one, try to match a pre-created property.
                // If that fails, then create a new property.
                //
                PropertyDescriptor[] values = new PropertyDescriptor[properties.Count];
                properties.CopyTo(values, 0);

                for (int i = 0; i < values.Length; i++)
                {
                    PropertyDescriptor prop = values[i];

                    // Skip some properties
                    //
                    if (object.Equals(prop.Attributes[typeof(DesignOnlyAttribute)], DesignOnlyAttribute.Yes))
                    {
                        continue;
                    }

                    if (prop.SerializationVisibility == DesignerSerializationVisibility.Hidden && !prop.IsBrowsable)
                    {
                        continue;
                    }

                    PropertyDescriptor inheritedProp = (PropertyDescriptor)props[prop.Name];

                    if (inheritedProp == null)
                    {
                        // This ia a publicly inherited component.  We replace all component properties with
                        // inherited versions that reset the default property values to those that are
                        // currently on the component.
                        //
                        props[prop.Name] = new InheritedPropertyDescriptor(prop, component, rootComponent);
                    }
                }
            }

            inheritedProps = props;
        }
Exemplo n.º 30
0
        private void ExtractInheritanceType()
        {
            System.Type element = Clazz;

            InheritanceAttribute      inhAnn           = AttributeHelper.GetFirst <InheritanceAttribute>(element);
            MappedSuperclassAttribute mappedSuperClass = AttributeHelper.GetFirst <MappedSuperclassAttribute>(element);

            if (mappedSuperClass != null)
            {
                IsEmbeddableSuperclass = true;
                type = inhAnn == null ? null : inhAnn.Strategy;
            }
            else
            {
                type = inhAnn == null ? InheritanceType.SingleTable  : inhAnn.Strategy;
            }
        }