NuGet.ManifestSchemaUtility.GetManifestSchemaSet C# (CSharp) Méthode

GetManifestSchemaSet() public static méthode

public static GetManifestSchemaSet ( string schemaNamespace ) : XmlSchemaSet
schemaNamespace string
Résultat System.Xml.Schema.XmlSchemaSet
        public static XmlSchemaSet GetManifestSchemaSet(string schemaNamespace)
        {
            return _manifestSchemaSetCache.GetOrAdd(schemaNamespace, schema =>
            {
                const string schemaResourceName = "NuGet.Authoring.nuspec.xsd";

                string formattedContent;

                // Update the xsd with the right schema namespace
                var assembly = typeof(Manifest).Assembly;
                using (var reader = new StreamReader(assembly.GetManifestResourceStream(schemaResourceName)))
                {
                    string content = reader.ReadToEnd();
                    formattedContent = String.Format(CultureInfo.InvariantCulture, content, schema);
                }

                using (var reader = new StringReader(formattedContent))
                {
                    var schemaSet = new XmlSchemaSet();
                    schemaSet.Add(schema, XmlReader.Create(reader));
                    return schemaSet;
                }
            });
        }

Usage Example

Exemple #1
0
        private static void ValidateManifestSchema(XDocument document, string schemaNamespace)
        {
            XmlSchemaSet manifestSchemaSet = ManifestSchemaUtility.GetManifestSchemaSet(schemaNamespace);

            document.Validate(manifestSchemaSet, delegate(object sender, ValidationEventArgs e) {
                if (e.Severity == XmlSeverityType.Error)
                {
                    throw new InvalidOperationException(e.Message);
                }
            });
        }
All Usage Examples Of NuGet.ManifestSchemaUtility::GetManifestSchemaSet