/// <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 assembly metadata.
        /// </summary>
        /// <param name="asmElement">The XML node that defines the assembly metadata.</param>
        private static void ProcessMetadataAssembly(XElement asmElement)
        {
            var name = asmElement.AttributeValueString("Name");
            if (String.IsNullOrEmpty(name))
                throw new InvalidOperationException("Invalid assembly name.");

            var types = asmElement.Element("Types");
            if (types != null)
            {
                foreach (var typeElement in types.Elements("Type"))
                {
                    ProcessMetadataType(name, typeElement);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ContentManifestAsset"/> class.
        /// </summary>
        /// <param name="group">The <see cref="ContentManifestGroup"/> that owns the asset.</param>
        /// <param name="element">The XML element that defines the asset.</param>
        internal ContentManifestAsset(ContentManifestGroup group, XElement element)
        {
            Contract.Require(element, "element");

            var name = element.AttributeValueString("Name");
            if (String.IsNullOrEmpty(name))
                throw new InvalidDataException(UltravioletStrings.InvalidContentManifestAssetName);

            var path = element.Value;
            if (String.IsNullOrEmpty(path))
                throw new InvalidDataException(UltravioletStrings.InvalidContentManifestAssetPath.Format(name));

            this.ManifestGroup = group;
            this.Name = name;
            this.RelativePath = path;
            this.AbsolutePath = Path.Combine(group.Directory, path);
            this.Type = group.Type;
        }
        /// <summary>
        /// Creates a set of localized strings from the specified XML element.
        /// </summary>
        /// <param name="xml">The XML element that contains the string definition.</param>
        /// <param name="strings">The dictionary to populate with strings for each loaded culture.</param>
        /// <returns>The localization key for the created strings.</returns>
        internal static String CreateFromXml(XElement xml, Dictionary<String, LocalizedString> strings)
        {
            Contract.Require(xml, "xml");
            Contract.Require(strings, "strings");

            strings.Clear();

            var key = xml.AttributeValueString("Key");
            if (String.IsNullOrEmpty(key))
                throw new InvalidDataException(NucleusStrings.LocalizedStringMissingKey);

            var html   = xml.AttributeValueBoolean("Html") ?? false;
            var pseudo = xml.AttributeValueBoolean("Pseudo") ?? true;

            var cultures = xml.Elements();
            foreach (var culture in cultures)
            {
                var cultureName = culture.Name.LocalName;
                var cultureString = new LocalizedString(cultureName, key, html, !pseudo);

                var stringPropertiesAttr = culture.Attribute("Properties");
                if (stringPropertiesAttr != null)
                {
                    var stringProperties = stringPropertiesAttr.Value.Split(',').Select(x => x.Trim());
                    foreach (var stringProperty in stringProperties)
                    {
                        cultureString.properties.Add(stringProperty, true);
                    }
                }

                var variants = culture.Elements("Variant");
                foreach (var variant in variants)
                {
                    var variantGroup = variant.AttributeValueString("Group") ?? "none";
                    var variantValue = variant.Value;
                    var variantProps = (variant.AttributeValueString("Properties") ?? String.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());

                    cultureString.variants[variantGroup] = new LocalizedStringVariant(cultureString, variantGroup, variantValue, variantProps);
                }

                strings[cultureName] = cultureString;
            }

            return key;
        }
 /// <summary>
 /// Creates an instance of EditorAttribute from the specified XML element.
 /// </summary>
 /// <param name="element">The XML element from which to create the attribute.</param>
 /// <returns>The attribute that was created.</returns>
 private static Attribute CreateEditorAttribute(XElement element)
 {
     var editorType = Type.GetType(element.Value);
     var editorBaseType = Type.GetType(element.AttributeValueString("BaseTypeName") ?? typeof(UITypeEditor).AssemblyQualifiedName);
     return new EditorAttribute(editorType, editorBaseType);
 }