Browse Source

Consolidate duplicated code into XmlDocLoader

pull/2936/head
Christoph Wille 2 years ago
parent
commit
2ddab6c54c
  1. 8
      ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs
  2. 41
      ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs

8
ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs

@ -104,7 +104,11 @@ namespace ICSharpCode.Decompiler.Documentation @@ -104,7 +104,11 @@ namespace ICSharpCode.Decompiler.Documentation
return fileName;
}
static string LookupLocalizedXmlDoc(string fileName)
/// <summary>
/// Given the assembly file name, looks up the XML documentation file name.
/// Returns null if no XML documentation file is found.
/// </summary>
internal static string LookupLocalizedXmlDoc(string fileName)
{
if (string.IsNullOrEmpty(fileName))
return null;
@ -135,7 +139,7 @@ namespace ICSharpCode.Decompiler.Documentation @@ -135,7 +139,7 @@ namespace ICSharpCode.Decompiler.Documentation
return null;
}
static string GetLocalizedName(string fileName, string language)
private static string GetLocalizedName(string fileName, string language)
{
string localizedXmlDocFile = Path.GetDirectoryName(fileName);
localizedXmlDocFile = Path.Combine(localizedXmlDocFile, language);

41
ICSharpCode.Decompiler/Documentation/XmlDocumentationProvider.cs

@ -185,7 +185,7 @@ namespace ICSharpCode.Decompiler.Documentation @@ -185,7 +185,7 @@ namespace ICSharpCode.Decompiler.Documentation
.Replace("%CORSYSDIR%", corSysDir);
if (!Path.IsPathRooted(fileName))
fileName = Path.Combine(Path.GetDirectoryName(xmlFileName), fileName);
return LookupLocalizedXmlDoc(fileName);
return XmlDocLoader.LookupLocalizedXmlDoc(fileName);
}
static string AppendDirectorySeparator(string dir)
@ -196,45 +196,6 @@ namespace ICSharpCode.Decompiler.Documentation @@ -196,45 +196,6 @@ namespace ICSharpCode.Decompiler.Documentation
return dir + Path.DirectorySeparatorChar;
}
/// <summary>
/// Given the assembly file name, looks up the XML documentation file name.
/// Returns null if no XML documentation file is found.
/// </summary>
public static string LookupLocalizedXmlDoc(string fileName)
{
string xmlFileName = Path.ChangeExtension(fileName, ".xml");
string currentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
string localizedXmlDocFile = GetLocalizedName(xmlFileName, currentCulture);
Debug.WriteLine("Try find XMLDoc @" + localizedXmlDocFile);
if (File.Exists(localizedXmlDocFile))
{
return localizedXmlDocFile;
}
Debug.WriteLine("Try find XMLDoc @" + xmlFileName);
if (File.Exists(xmlFileName))
{
return xmlFileName;
}
if (currentCulture != "en")
{
string englishXmlDocFile = GetLocalizedName(xmlFileName, "en");
Debug.WriteLine("Try find XMLDoc @" + englishXmlDocFile);
if (File.Exists(englishXmlDocFile))
{
return englishXmlDocFile;
}
}
return null;
}
static string GetLocalizedName(string fileName, string language)
{
string localizedXmlDocFile = Path.GetDirectoryName(fileName);
localizedXmlDocFile = Path.Combine(localizedXmlDocFile, language);
localizedXmlDocFile = Path.Combine(localizedXmlDocFile, Path.GetFileName(fileName));
return localizedXmlDocFile;
}
#endregion
#region Load / Create Index

Loading…
Cancel
Save