From 02020b11647411411e61b3ce7cad23c515d2cfea Mon Sep 17 00:00:00 2001 From: Laszlo Paillat Date: Sun, 10 May 2020 19:05:51 +0200 Subject: [PATCH] fixed see element with langword attribute usage --- .../DefaultDocumentation.Release.csproj | 2 ++ .../DocumentationWriter.cs | 19 ++++++++++++++++++- .../Helper/XElementExtension.cs | 4 +++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/source/DefaultDocumentation/DefaultDocumentation.Release.csproj b/source/DefaultDocumentation/DefaultDocumentation.Release.csproj index aa926fc4..7adc9de9 100644 --- a/source/DefaultDocumentation/DefaultDocumentation.Release.csproj +++ b/source/DefaultDocumentation/DefaultDocumentation.Release.csproj @@ -10,6 +10,8 @@ 0.6.3 added DefaultDocumentationNestedTypeVisibility parameter to set where nested types are displayed (possible value: Namespace, DeclaringType,Everywhere) + +fixed see element with langword attribute usage \ No newline at end of file diff --git a/source/DefaultDocumentation/DocumentationWriter.cs b/source/DefaultDocumentation/DocumentationWriter.cs index e54aba78..8fb78890 100644 --- a/source/DefaultDocumentation/DocumentationWriter.cs +++ b/source/DefaultDocumentation/DocumentationWriter.cs @@ -171,6 +171,23 @@ public void WriteDocItems(string title) public void Write(string title, XElement element, DocItem item) { + string GetSeeLink(XElement element) + { + string see = element.GetReferenceName(); + if (see is null) + { + see = element.GetLangWord(); + if (see is null) + { + return string.Empty; + } + + return $"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/{see}"; + } + + return GetLink(see); + } + string WriteNodes(IEnumerable nodes) { return string.Concat(nodes.Select(node => node switch @@ -178,7 +195,7 @@ string WriteNodes(IEnumerable nodes) XText text => string.Join(" \n", text.Value.Split('\n')), XElement element => element.Name.ToString() switch { - "see" => GetLink(element.GetReferenceName()), + "see" => GetSeeLink(element), "seealso" => GetLink(element.GetReferenceName()), "typeparamref" => item.TryGetTypeParameterDocItem(element.GetName(), out TypeParameterDocItem typeParameter) ? GetInnerLink(typeParameter) : element.GetName(), "paramref" => item.TryGetParameterDocItem(element.GetName(), out ParameterDocItem parameter) ? GetInnerLink(parameter) : element.GetName(), diff --git a/source/DefaultDocumentation/Helper/XElementExtension.cs b/source/DefaultDocumentation/Helper/XElementExtension.cs index 27920f8b..c89b6804 100644 --- a/source/DefaultDocumentation/Helper/XElementExtension.cs +++ b/source/DefaultDocumentation/Helper/XElementExtension.cs @@ -23,6 +23,8 @@ internal static class XElementExtension public static string GetName(this XElement element) => element.Attribute("name")?.Value; - public static string GetReferenceName(this XElement element) => element.Attribute("cref").Value; + public static string GetReferenceName(this XElement element) => element.Attribute("cref")?.Value; + + public static string GetLangWord(this XElement element) => element.Attribute("langword")?.Value; } }