private MetadataItemSerializer(XmlWriter writer, bool isModel, ErrorsLookup errorsLookup, Version schemaVersion) { _writer = writer; _isModel = isModel; _errorsLookup = errorsLookup; _schemaVersion = schemaVersion; }
internal static void WriteXml(XmlWriter writer, ItemCollection collection, string namespaceToWrite, ErrorsLookup errorsLookup, List <EdmType> commentedOutItems, string provider, string providerManifestToken, Version schemaVersion, params KeyValuePair <string, string>[] xmlPrefixToNamespaces) { Debug.Assert(writer != null, "writer parameter is null"); Debug.Assert(collection != null, "collection parameter is null"); Debug.Assert(errorsLookup != null, "errorsLookup parameter is null"); Debug.Assert(!string.IsNullOrEmpty(namespaceToWrite), "namespaceToWrite parameter is null or empty"); MetadataItemSerializer serializer = new MetadataItemSerializer(writer, collection.DataSpace == DataSpace.CSpace, errorsLookup, schemaVersion); serializer.ValidateNamespace(namespaceToWrite); serializer.WriteSchemaElement(namespaceToWrite, provider, providerManifestToken, xmlPrefixToNamespaces); serializer.WriteErrorsComment(NoSpecificTypeSentinal); foreach (EntityContainer item in collection.GetItems <EntityContainer>()) { serializer.WriteEntityContainerElement(item); } foreach (EdmType type in collection.GetItems <EdmType>()) { // is it in the right space (c or s) // does it have the right namespace? if (type.NamespaceName == namespaceToWrite) { serializer.WriteTypeElement(type); } } if (commentedOutItems.Count > 0) { StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.OmitXmlDeclaration = true; // we can have more than one commented out type // which will look like multiple root elements, so this is a fragment settings.ConformanceLevel = ConformanceLevel.Fragment; XmlWriter commentWriter = XmlWriter.Create(stringWriter, settings); MetadataItemSerializer commmentSerializer = new MetadataItemSerializer(commentWriter, collection.DataSpace == DataSpace.CSpace, errorsLookup, schemaVersion); foreach (EdmType type in commentedOutItems) { commmentSerializer.WriteTypeElement(type); } commentWriter.Flush(); //This is not the cleanest thing to do but XmlTextWriter //does not allow writing xml comment characters while writing a comment. //and since we know exactly the string we write, this is pretty safe. string comment = RemoveXmlCommentCharacters(stringWriter); writer.WriteComment(comment); } writer.WriteEndElement(); }