1 //---------------------------------------------------------------------
2 // <copyright file="MetadataArtifactLoaderXmlReaderWrapper.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 using System.Collections.Generic;
11 using System.Collections;
12 using System.Diagnostics;
15 using System.Security.Permissions;
18 namespace System.Data.Metadata.Edm
21 /// This class represents a wrapper around an XmlReader to be used to load metadata.
22 /// Note that the XmlReader object isn't created here -- the wrapper simply stores
23 /// a reference to it -- therefore we do not Close() the reader when we Dispose()
24 /// the wrapper, i.e., Dispose() is a no-op.
26 internal class MetadataArtifactLoaderXmlReaderWrapper : MetadataArtifactLoader, IComparable
28 private readonly XmlReader _reader = null;
29 private readonly string _resourceUri = null;
32 /// Constructor - saves off the XmlReader in a private data field
34 /// <param name="xmlReader">The path to the resource to load</param>
35 public MetadataArtifactLoaderXmlReaderWrapper(XmlReader xmlReader)
38 _resourceUri = xmlReader.BaseURI;
42 public override string Path
46 if (string.IsNullOrEmpty(this._resourceUri))
52 return this._resourceUri;
58 /// Implementation of IComparable.CompareTo()
60 /// <param name="obj">The object to compare to</param>
61 /// <returns>0 if the loaders are "equal" (i.e., have the same _path value)</returns>
62 public int CompareTo(object obj)
64 MetadataArtifactLoaderXmlReaderWrapper loader = obj as MetadataArtifactLoaderXmlReaderWrapper;
67 if (Object.ReferenceEquals(this._reader, loader._reader))
77 Debug.Assert(false, "object is not a MetadataArtifactLoaderXmlReaderWrapper");
82 /// Equals() returns true if the objects have the same _path value
84 /// <param name="obj">The object to compare to</param>
85 /// <returns>true if the objects have the same _path value</returns>
86 public override bool Equals(object obj)
88 return this.CompareTo(obj) == 0;
92 /// GetHashCode override that defers the result to the _path member variable.
94 /// <returns></returns>
95 public override int GetHashCode()
97 return _reader.GetHashCode();
100 public override void CollectFilePermissionPaths(List<string> paths, DataSpace spaceToGet)
106 /// Get paths to artifacts for a specific DataSpace.
108 /// <param name="spaceToGet">The DataSpace for the artifacts of interest</param>
109 /// <returns>A List of strings identifying paths to all artifacts for a specific DataSpace</returns>
110 public override List<string> GetPaths(DataSpace spaceToGet)
112 List<string> list = new List<string>();
113 if (MetadataArtifactLoader.IsArtifactOfDataSpace(Path, spaceToGet))
121 /// Get paths to all artifacts
123 /// <returns>A List of strings identifying paths to all resources</returns>
124 public override List<string> GetPaths()
126 return new List<string>(new string[] { Path });
130 /// Get XmlReaders for all resources
132 /// <returns>A List of XmlReaders for all resources</returns>
133 public override List<XmlReader> GetReaders(Dictionary<MetadataArtifactLoader, XmlReader> sourceDictionary)
135 List<XmlReader> list = new List<XmlReader>();
137 list.Add(this._reader);
138 if (sourceDictionary != null)
140 sourceDictionary.Add(this, _reader);
147 /// Create and return an XmlReader around the resource represented by this instance
148 /// if it is of the requested DataSpace type.
150 /// <param name="spaceToGet">The DataSpace corresponding to the requested artifacts</param>
151 /// <returns>A List of XmlReader objects</returns>
152 public override List<XmlReader> CreateReaders(DataSpace spaceToGet)
154 List<XmlReader> list = new List<XmlReader>();
156 if (MetadataArtifactLoader.IsArtifactOfDataSpace(Path, spaceToGet))