NuGet.ManifestSchemaUtility.GetSchemaNamespace C# (CSharp) Method

GetSchemaNamespace() public static method

public static GetSchemaNamespace ( int version ) : string
version int
return string
        public static string GetSchemaNamespace(int version)
        {
            // Versions are internally 0-indexed but stored with a 1 index so decrement it by 1
            if (version <= 0 || version > VersionToSchemaMappings.Length)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, NuGetResources.UnknownSchemaVersion, version));
            }
            return VersionToSchemaMappings[version - 1];
        }

Usage Example

Exemplo n.º 1
0
        public void Save(Stream stream, bool validate, int minimumManifestVersion)
        {
            if (validate)
            {
                // Validate before saving
                Validate(this);
            }

            int    version         = Math.Max(minimumManifestVersion, ManifestVersionUtility.GetManifestVersion(Metadata));
            string schemaNamespace = ManifestSchemaUtility.GetSchemaNamespace(version);

            // Define the namespaces to use when serializing
            var ns = new XmlSerializerNamespaces();

            ns.Add("", schemaNamespace);

            // Need to force the namespace here again as the default in order to get the XML output clean
            var serializer = new XmlSerializer(typeof(Manifest), schemaNamespace);

            using (var xmlWriter = new XmlTextWriter(stream, Encoding.UTF8))
            {
                xmlWriter.Indentation = 4;
                xmlWriter.Formatting  = Formatting.Indented;
                serializer.Serialize(xmlWriter, this, ns);
            }
        }
All Usage Examples Of NuGet.ManifestSchemaUtility::GetSchemaNamespace