-
Notifications
You must be signed in to change notification settings - Fork 3
/
XrefMapReference.cs
99 lines (76 loc) · 3.07 KB
/
XrefMapReference.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Collections.Generic;
using System.Text.RegularExpressions;
using YamlDotNet.Serialization;
namespace DocFxForUnity
{
/// <summary>
/// Represents a reference item on a <see cref="XrefMap"/>.
/// </summary>
public sealed partial class XrefMapReference
{
/// <summary>
/// The online API documentation of Unity doesn't show some namespaces.
/// </summary>
private static readonly List<string> HrefNamespacesToTrim = new() { "UnityEditor", "UnityEngine" };
[GeneratedRegex("`{2}\\d")]
private static partial Regex GenericHrefRegex();
[GeneratedRegex("\\*$")]
private static partial Regex MethodHrefPointerRegex();
[GeneratedRegex("\\(.*\\)")]
private static partial Regex MethodHrefRegex();
[GeneratedRegex("\\.([a-z].*)$")]
private static partial Regex PropertyHrefRegex();
public string uid { get; set; }
public string name { get; set; }
[YamlMember(Alias = "name.vb")]
public string nameVb { get; set; }
public string href { get; set; }
public string commentId { get; set; }
public string isSpec { get; set; }
public string fullName { get; set; }
[YamlMember(Alias = "fullName.vb")]
public string fullNameVb { get; set; }
public string nameWithType { get; set; }
[YamlMember(Alias = "nameWithType.vb")]
public string nameWithTypeVb { get; set; }
/// <summary>
/// Gets if this <see cref="XrefMapReference"/> is valid or not.
/// </summary>
public bool IsValid => !commentId.Contains("Overload:");
/// <summary>
/// Sets <see cref="href"/> to link to the online API documentation of Unity.
/// </summary>
/// <param name="apiUrl">The URL of the online API documentation of Unity.</param>
public void FixHref(string apiUrl)
{
// Namespaces point to documentation index
if (commentId.Contains("N:"))
{
href = "index";
}
else
{
href = uid;
// Trim UnityEngine and UnityEditor namespaces from href
foreach (var hrefNamespaceToTrim in HrefNamespacesToTrim)
{
href = href.Replace(hrefNamespaceToTrim + ".", "");
}
// Fix href of constructors
href = href.Replace(".#ctor", "-ctor");
// Fix href of generics
href = GenericHrefRegex().Replace(href, "");
href = href.Replace("`", "_");
// Fix href of methods
href = MethodHrefPointerRegex().Replace(href, "");
href = MethodHrefRegex().Replace(href, "");
// Fix href of properties
if (commentId.Contains("P:") || commentId.Contains("M:"))
{
href = PropertyHrefRegex().Replace(href, "-$1");
}
}
href = apiUrl + href + ".html";
}
}
}