forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlossaryHelpInfo.cs
More file actions
168 lines (135 loc) · 5 KB
/
Copy pathGlossaryHelpInfo.cs
File metadata and controls
168 lines (135 loc) · 5 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System.Xml;
using System.Text;
using System.Diagnostics.CodeAnalysis;
namespace System.Management.Automation
{
/// <summary>
///
/// Class GlossaryHelpInfo keeps track of help information to be returned by
/// glossary help provider.
///
/// </summary>
internal class GlossaryHelpInfo : HelpInfo
{
/// <summary>
/// Constructor for GlossaryHelpInfo
/// </summary>
/// <remarks>
/// This constructor is can be called only from constructors of derived class
/// for GlossaryHelpInfo. The only way to to create a GlossaryHelpInfo is through
/// static function
/// Load(XmlNode node)
/// where some sanity check is done.
/// </remarks>
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "This is internal code and is verified.")]
protected GlossaryHelpInfo(XmlNode xmlNode)
{
MamlNode mamlNode = new MamlNode(xmlNode);
_fullHelpObject = mamlNode.PSObject;
this.Errors = mamlNode.Errors;
Name = GetTerm();
_fullHelpObject.TypeNames.Clear();
_fullHelpObject.TypeNames.Add(string.Format(Globalization.CultureInfo.InvariantCulture,
"GlossaryHelpInfo#{0}", Name));
_fullHelpObject.TypeNames.Add("GlossaryHelpInfo");
_fullHelpObject.TypeNames.Add("HelpInfo");
}
#region Basic Help Properties
/// <summary>
/// Name of glossary.
/// </summary>
/// <value>Name of glossary</value>
internal override string Name { get; } = "";
private string GetTerm()
{
if (_fullHelpObject == null)
return "";
if (_fullHelpObject.Properties["Terms"] == null)
return "";
if (_fullHelpObject.Properties["Terms"].Value == null)
return "";
PSObject terms = (PSObject)_fullHelpObject.Properties["Terms"].Value;
if (terms.Properties["Term"] == null)
return "";
if (terms.Properties["Term"].Value == null)
return "";
if (terms.Properties["Term"].Value.GetType().Equals(typeof(PSObject)))
{
PSObject term = (PSObject)terms.Properties["Term"].Value;
return term.ToString();
}
if (terms.Properties["Term"].Value.GetType().Equals(typeof(PSObject[])))
{
PSObject[] term = (PSObject[])terms.Properties["Term"].Value;
StringBuilder result = new StringBuilder();
for (int i = 0; i < term.Length; i++)
{
string str = term[i].ToString();
if (str == null)
continue;
str = str.Trim();
if (String.IsNullOrEmpty(str))
continue;
if (result.Length > 0)
result.Append(", ");
result.Append(str);
}
return result.ToString();
}
return "";
}
/// <summary>
/// Synopsis for this glossary help.
/// </summary>
/// <value>Synopsis for this glossary help</value>
internal override string Synopsis
{
get
{
return "";
}
}
/// <summary>
/// Help category for this glossary help, which is constantly HelpCategory.Glossary.
/// </summary>
/// <value>Help category for this glossary help</value>
internal override HelpCategory HelpCategory
{
get
{
return HelpCategory.Glossary;
}
}
private PSObject _fullHelpObject;
/// <summary>
/// Full help object for this help item.
/// </summary>
/// <value>Full help object for this help item.</value>
internal override PSObject FullHelp
{
get
{
return _fullHelpObject;
}
}
#endregion
#region Load
/// <summary>
/// Create a GlossaryHelpInfo object from an XmlNode.
/// </summary>
/// <param name="xmlNode">xmlNode that contains help info</param>
/// <returns>GlossaryHelpInfo object created</returns>
internal static GlossaryHelpInfo Load(XmlNode xmlNode)
{
GlossaryHelpInfo glossaryHelpInfo = new GlossaryHelpInfo(xmlNode);
if (String.IsNullOrEmpty(glossaryHelpInfo.Name))
return null;
glossaryHelpInfo.AddCommonHelpProperties();
return glossaryHelpInfo;
}
#endregion
}
}