-
Notifications
You must be signed in to change notification settings - Fork 365
/
ReferenceLinkInfo.cs
153 lines (122 loc) · 6.64 KB
/
ReferenceLinkInfo.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//===============================================================================================================
// System : Sandcastle Build Components
// File : ReferenceLinkInfo.cs
// Note : Copyright 2010-2021 Microsoft Corporation
//
// This file contains the ReferenceLinkInfo class used to hold reference link information used by the
// ResolveReferenceLinksComponent.
//
// This code is published under the Microsoft Public License (Ms-PL). A copy of the license should be
// distributed with the code and can be found at the project website: https://GitHub.com/EWSoftware/SHFB. This
// notice and all copyright notices must remain intact in all applications, documentation, and source files.
//
// Change History
// 12/28/2012 - EFW - Moved the class into the Targets namespace. Removed the static Create() method and moved
// the code it contained into the constructor and made it public.
// 03/17/2013 - EFW - Added support for the syntax writer renderAsLink attribute
//===============================================================================================================
using System;
using System.Xml.XPath;
namespace Sandcastle.Tools.BuildComponents.Targets
{
/// <summary>
/// This class is used to hold reference link information used by the
/// <see cref="ResolveReferenceLinksComponent"/>.
/// </summary>
public class ReferenceLinkInfo
{
#region Properties
//=====================================================================
/// <summary>This read-only property returns the target of the link</summary>
public string Target { get; }
/// <summary>This read-only property returns the display target of the link</summary>
public string DisplayTarget { get; internal set; }
/// <summary>This read-only property returns the display options for the link</summary>
public DisplayOptions DisplayOptions { get; }
/// <summary>This read-only property indicates whether or not to prefer the overload topic</summary>
public bool PreferOverload { get; }
/// <summary>
/// This read-only property indicates whether or not to render the element as an actual link
/// </summary>
/// <value>If true, it is rendered as a link. If false, it will be rendered as an identifier.</value>
public bool RenderAsLink { get; }
/// <summary>This read-only property returns the contents of the link</summary>
public XPathNavigator Contents { get; internal set; }
#endregion
#region Methods, etc.
//=====================================================================
/// <summary>
/// Constructor
/// </summary>
/// <param name="element">The XPath navigator from which to load the link settings</param>
/// <exception cref="ArgumentNullException">This is thrown if the element parameters is null</exception>
/// <exception cref="InvalidOperationException">This is thrown if the element contains invalid
/// configuration information.</exception>
public ReferenceLinkInfo(XPathNavigator element)
{
bool attrValue;
if(element == null)
throw new ArgumentNullException(nameof(element));
this.DisplayOptions = DisplayOptions.Default;
this.Target = element.GetAttribute("target", String.Empty);
this.DisplayTarget = element.GetAttribute("display-target", String.Empty);
string showContainer = element.GetAttribute("show-container", String.Empty);
if(String.IsNullOrEmpty(showContainer))
showContainer = element.GetAttribute("qualified", String.Empty);
if(!String.IsNullOrEmpty(showContainer))
{
if(!Boolean.TryParse(showContainer, out attrValue))
throw new InvalidOperationException("The show-container or qualified attribute does not " +
"contain a valid Boolean value");
if(attrValue)
this.DisplayOptions |= DisplayOptions.ShowContainer;
else
this.DisplayOptions &= ~DisplayOptions.ShowContainer;
}
string showTemplates = element.GetAttribute("show-templates", String.Empty);
if(!String.IsNullOrEmpty(showTemplates))
{
if(!Boolean.TryParse(showTemplates, out attrValue))
throw new InvalidOperationException("The show-templates attribute does not contain a " +
"valid Boolean value");
if(attrValue)
this.DisplayOptions |= DisplayOptions.ShowTemplates;
else
this.DisplayOptions &= ~DisplayOptions.ShowTemplates;
}
string showParameters = element.GetAttribute("show-parameters", String.Empty);
if(!String.IsNullOrEmpty(showParameters))
{
if(!Boolean.TryParse(showParameters, out attrValue))
throw new InvalidOperationException("The show-parameters attribute does not contain a " +
"valid Boolean value");
if(attrValue)
this.DisplayOptions |= DisplayOptions.ShowParameters;
else
this.DisplayOptions &= ~DisplayOptions.ShowParameters;
}
string preferOverload = element.GetAttribute("prefer-overload", String.Empty);
if(String.IsNullOrEmpty(preferOverload))
preferOverload = element.GetAttribute("auto-upgrade", String.Empty);
if(!String.IsNullOrEmpty(preferOverload))
{
if(!Boolean.TryParse(preferOverload, out attrValue))
throw new InvalidOperationException("The prefer-overload or auto-upgrade attribute does " +
"not contain a valid Boolean value");
if(attrValue)
this.PreferOverload = true;
else
this.PreferOverload = false;
}
string renderAsLink = element.GetAttribute("renderAsLink", String.Empty);
if(String.IsNullOrWhiteSpace(renderAsLink) || !Boolean.TryParse(renderAsLink, out attrValue))
this.RenderAsLink = true;
else
this.RenderAsLink = attrValue;
this.Contents = element.Clone();
if(!this.Contents.MoveToFirstChild())
this.Contents = null;
}
#endregion
}
}