Skip to content

Commit

Permalink
Refactor ComponentDesigner to use Dictionary<TKey, TValue> instead of…
Browse files Browse the repository at this point in the history
… Hashtable (#8221)

* Refactor ComponentDesigner to to use Dictionary<TKey, TValue> instead of Hashtable

* Indicate the type of elements in foreach loop
  • Loading branch information
Jericho authored Nov 18, 2022
1 parent 572929b commit c9e06c2
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace System.ComponentModel.Design
public partial class ComponentDesigner : ITreeDesigner, IDesignerFilter, IComponentInitializer
{
private InheritanceAttribute _inheritanceAttribute;
private Hashtable _inheritedProps;
private Dictionary<string, InheritedPropertyDescriptor> _inheritedProps;
private DesignerVerbCollection _verbs;
private DesignerActionListCollection _actionLists;
private ShadowPropertyCollection _shadowProperties;
Expand Down Expand Up @@ -365,7 +365,7 @@ public virtual void Initialize(IComponent component)

private void InitializeInheritedProperties()
{
Hashtable props = new Hashtable();
Dictionary<string, InheritedPropertyDescriptor> props = new();
InheritanceAttribute inheritanceAttribute = InheritanceAttribute;
bool readOnlyInherit = inheritanceAttribute is not null && inheritanceAttribute.Equals(InheritanceAttribute.InheritedReadOnly);

Expand Down Expand Up @@ -393,13 +393,11 @@ private void InitializeInheritedProperties()
continue;
}

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

if (inheritedProp is null)
if (!props.ContainsKey(prop.Name))
{
// 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);
props.Add(prop.Name, new(prop, Component));
}
}
}
Expand Down Expand Up @@ -656,17 +654,15 @@ protected virtual void PostFilterProperties(IDictionary properties)
}

// otherwise apply our inherited properties to the actual property list.
foreach (DictionaryEntry de in _inheritedProps)
foreach (KeyValuePair<string, InheritedPropertyDescriptor> de in _inheritedProps)
{
if (de.Value is InheritedPropertyDescriptor inheritedPropDesc)
// 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 is not 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 is not null)
{
inheritedPropDesc.PropertyDescriptor = newInnerProp;
properties[de.Key] = inheritedPropDesc;
}
InheritedPropertyDescriptor inheritedPropDesc = de.Value;
inheritedPropDesc.PropertyDescriptor = newInnerProp;
properties[de.Key] = inheritedPropDesc;
}
}
}
Expand Down

0 comments on commit c9e06c2

Please sign in to comment.