Inheritance: CoalesceFile
示例#1
0
        public static XmlCoalesceFile Load(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            var sourcePath = Path.GetFullPath(path);

            if (!File.Exists(sourcePath))
            {
                return(null);
            }

            var doc = XDocument.Load(path);

            var result = new XmlCoalesceFile
            {
                BaseUri         = doc.BaseUri != "" ? doc.BaseUri : new Uri(sourcePath).AbsoluteUri,
                SourcePath      = sourcePath,
                SourceDirectory = Path.GetDirectoryName(sourcePath)
            };

            // Read settings before assets
            result.ReadSettings(doc);
            result.ReadAssets(doc);

            return(result);
        }
		public static XmlCoalesceFile Load(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				throw new ArgumentNullException(nameof(path));
			}

			var sourcePath = Path.GetFullPath(path);

			if (!File.Exists(sourcePath))
			{
				return null;
			}

			var doc = XDocument.Load(path);
			
			var result = new XmlCoalesceFile
			{
				BaseUri = (doc.BaseUri != "") ? doc.BaseUri : new Uri(sourcePath).AbsoluteUri,
				SourcePath = sourcePath,
				SourceDirectory = Path.GetDirectoryName(sourcePath)
			};

			// Read settings before assets
			result.ReadSettings(doc);
			result.ReadAssets(doc);

			return result;
		}
        /// <summary>
        /// Loads a coalesced file from XML that has already been parsed into an XDocument. Use to avoid double parsing the file
        /// </summary>
        /// <param name="sourcePath"></param>
        /// <param name="doc"></param>
        public static XmlCoalesceFile LoadXmlDocument(string sourcePath, XDocument doc)
        {
            var result = new XmlCoalesceFile
            {
                BaseUri         = doc.BaseUri != "" ? doc.BaseUri : new Uri(sourcePath).AbsoluteUri,
                SourcePath      = sourcePath,
                SourceDirectory = Path.GetDirectoryName(sourcePath)
            };

            // Read settings before assets
            result.ReadSettings(doc);
            result.ReadAssets(doc);

            return(result);
        }