/// <summary> /// Processes type metadata. /// </summary> /// <param name="asmName">The name of the current assembly.</param> /// <param name="typeElement">The XML node that defines the type metadata.</param> private static void ProcessMetadataType(String asmName, XElement typeElement) { var name = typeElement.AttributeValueString("Name"); if (String.IsNullOrEmpty(name)) throw new InvalidOperationException("Invalid type name."); var typeName = String.Format("{0}, {1}", name, asmName); var type = Type.GetType(typeName, false); if (type == null) throw new InvalidOperationException(String.Format("Invalid type name '{0}'", typeName)); var attributes = new List<Attribute>(); foreach (var attributeElement in typeElement.Elements()) { switch (attributeElement.Name.LocalName) { case "Editor": attributes.Add(CreateEditorAttribute(attributeElement)); break; case "TypeConverter": attributes.Add(CreateTypeConverterAttribute(attributeElement)); break; case "DefaultValue": attributes.Add(CreateDefaultValueAttribute(attributeElement, type)); break; case "Properties": break; default: throw new InvalidOperationException(String.Format("Invalid element '{0}' in '{1}'", attributeElement.Name.LocalName, typeName)); } } if (attributes.Any()) { TypeDescriptor.AddAttributes(type, attributes.ToArray()); } var properties = typeElement.Element("Properties"); var propertyDescriptors = new List<PropertyDescriptor>(); if (properties != null) { foreach (var propertyElement in properties.Elements()) { var propertyDescriptor = ProcessMetadataProperty(type, propertyElement); propertyDescriptors.Add(propertyDescriptor); } } var providerParent = TypeDescriptor.GetProvider(type); var provider = new XmlDrivenCustomTypeDescriptionProvider(providerParent, propertyDescriptors); TypeDescriptor.AddProvider(provider, type); }
/// <summary> /// Processes type metadata. /// </summary> /// <param name="asmName">The name of the current assembly.</param> /// <param name="typeElement">The XML node that defines the type metadata.</param> private static void ProcessMetadataType(String asmName, XElement typeElement) { var name = typeElement.AttributeValueString("Name"); if (String.IsNullOrEmpty(name)) { throw new InvalidOperationException("Invalid type name."); } var typeName = String.Format("{0}, {1}", name, asmName); var type = Type.GetType(typeName, false); if (type == null) { throw new InvalidOperationException(String.Format("Invalid type name '{0}'", typeName)); } var attributes = new List <Attribute>(); foreach (var attributeElement in typeElement.Elements()) { switch (attributeElement.Name.LocalName) { case "Editor": attributes.Add(CreateEditorAttribute(attributeElement)); break; case "TypeConverter": attributes.Add(CreateTypeConverterAttribute(attributeElement)); break; case "DefaultValue": attributes.Add(CreateDefaultValueAttribute(attributeElement, type)); break; case "Properties": break; default: throw new InvalidOperationException(String.Format("Invalid element '{0}' in '{1}'", attributeElement.Name.LocalName, typeName)); } } if (attributes.Any()) { TypeDescriptor.AddAttributes(type, attributes.ToArray()); } var properties = typeElement.Element("Properties"); var propertyDescriptors = new List <PropertyDescriptor>(); if (properties != null) { foreach (var propertyElement in properties.Elements()) { var propertyDescriptor = ProcessMetadataProperty(type, propertyElement); propertyDescriptors.Add(propertyDescriptor); } } var providerParent = TypeDescriptor.GetProvider(type); var provider = new XmlDrivenCustomTypeDescriptionProvider(providerParent, propertyDescriptors); TypeDescriptor.AddProvider(provider, type); }