/// <summary> /// Configures an <see cref="IAttributesConfigurable"/> component with the set of attributes specified. /// </summary> internal static void Configure(IAttributesConfigurable component, XmlAttribute[] attributes) { ImmutableKeyStringDictionary values = new ImmutableKeyStringDictionary(); if (attributes != null) { foreach (XmlAttribute xattr in attributes) { values.Add(xattr.Name, xattr.Value); } } component.Configure(values); }
/// <summary> /// Default constructor /// </summary> public CLRTypeEditor() { IAttributesConfigurable configurable = this as IAttributesConfigurable; if (configurable != null && this.Config != null) { StringDictionary parameters = new StringDictionary(); parameters[CodeModelEditor.BrowseKindAttribute] = Config.BrowseKind.ToString(); parameters[CodeModelEditor.BrowseRootAttribute] = Config.BrowseRoot.ToString(); if (Config.Filter != null) { string typeRefName = Config.Filter.FullName + "," + Config.Filter.Assembly.FullName; parameters[CodeModelEditor.FilterAttribute] = typeRefName; } configurable.Configure(parameters); } }
private void EnsureConfiguration(ITypeDescriptorContext context) { // check if we already loaded the converters if (context == null || this.converters.Count > 0) { return; } ITypeResolutionService resolution = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService)); if (resolution != null) { // look for converter types and load them foreach (DictionaryEntry attribute in this.configuredAttributes) { if (attribute.Key.ToString().StartsWith(AddConverterPrefixAttribute, StringComparison.InvariantCultureIgnoreCase)) { Type converterType = resolution.GetType(attribute.Value.ToString(), true, true); ReflectionHelper.EnsureAssignableTo(converterType, typeof(StringConverter)); // create an instance of this converter object converter = Activator.CreateInstance(converterType); // check if this converter implements IAttributesConfigurable if (ReflectionHelper.IsAssignableTo(typeof(IAttributesConfigurable), converter)) { IAttributesConfigurable configure = converter as IAttributesConfigurable; configure.Configure(this.configuredAttributes); } // store the StringConverter this.converters.Add((StringConverter)converter); } } // we reverse the collection because the attributes collection // will be ordered backward in the AgregatorStringConverter element . this.converters.Reverse(); } }