You've already forked linux-packaging-mono
Imported Upstream version 6.6.0.89
Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
This commit is contained in:
parent
cf815e07e0
commit
95fdb59ea6
71
external/api-doc-tools/mdoc/Mono.Documentation/Framework/FrameworkIndexHelper.cs
vendored
Normal file
71
external/api-doc-tools/mdoc/Mono.Documentation/Framework/FrameworkIndexHelper.cs
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Mono.Documentation.Framework
|
||||
{
|
||||
public static class FrameworkIndexHelper
|
||||
{
|
||||
public static Dictionary<string, FrameworkNamespaceModel> CreateFrameworkIndex(string path, string frameworkName)
|
||||
{
|
||||
string frameworkFilePath = GetFrameworkFilePath(path, frameworkName);
|
||||
if (!File.Exists(frameworkFilePath))
|
||||
{
|
||||
throw new ArgumentException($"Can't find framework file: {frameworkFilePath}");
|
||||
}
|
||||
using (XmlReader xmlReader = XmlReader.Create(frameworkFilePath))
|
||||
{
|
||||
return ReadFrameworkIndex(xmlReader);
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, FrameworkNamespaceModel> ReadFrameworkIndex(XmlReader xmlReader)
|
||||
{
|
||||
var dict = new Dictionary<string, FrameworkNamespaceModel>();
|
||||
|
||||
xmlReader.ReadToFollowing("Framework");
|
||||
xmlReader.ReadToDescendant("Namespace");
|
||||
|
||||
while (xmlReader.NodeType != XmlNodeType.EndElement)
|
||||
{
|
||||
XNode node = XNode.ReadFrom(xmlReader);
|
||||
XElement element = node as XElement;
|
||||
|
||||
if (element == null) continue;
|
||||
var ns = new FrameworkNamespaceModel(node);
|
||||
|
||||
dict.Add(ns.Name, ns);
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
private static string GetFrameworkFilePath(string path, string frameworkName)
|
||||
{
|
||||
string docsRoot = Path.GetDirectoryName(path) ?? "";
|
||||
string frameworksIndexPath = Path.Combine(docsRoot, Consts.FrameworksIndexFolderName);
|
||||
foreach (string frameworkIndexFilePath in Directory.EnumerateFiles(frameworksIndexPath))
|
||||
{
|
||||
using (XmlReader xmlReader = XmlReader.Create(frameworkIndexFilePath))
|
||||
{
|
||||
bool isFrameworkNodeFound = xmlReader.ReadToFollowing("Framework");
|
||||
if (!isFrameworkNodeFound)
|
||||
{
|
||||
throw new InvalidOperationException($"Invalid framework file format in {frameworkIndexFilePath}");
|
||||
}
|
||||
|
||||
var frameworkNameInFile = xmlReader.GetAttribute("Name");
|
||||
if (frameworkNameInFile == frameworkName)
|
||||
{
|
||||
return frameworkIndexFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidEnumArgumentException($"Can't find file for frameworkName = {frameworkName}");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user