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
|
using Mono.Cecil;
using Mono.Documentation.Updater.Frameworks;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
namespace Mono.Documentation
{
public partial class MDocUpdater
{
internal static void MakeTypeParameterConstraints(XmlElement root, XmlElement e, XmlElement pe, GenericParameter typeParameter)
{
if (typeParameter == null)
{
return;
}
#if NEW_CECIL
Mono.Collections.Generic.Collection<GenericParameterConstraint> constraints = typeParameter.Constraints;
#else
IList<TypeReference> constraints = typeParameter.Constraints;
#endif
GenericParameterAttributes attrs = typeParameter.Attributes;
XmlElement ce = (XmlElement)e.SelectSingleNode("Constraints");
if (attrs == GenericParameterAttributes.NonVariant && constraints.Count == 0)
{
if (ce != null)
e.RemoveChild(ce);
}
if (ce != null)
ce.RemoveAll();
else
{
ce = root.OwnerDocument.CreateElement("Constraints");
}
if ((attrs & GenericParameterAttributes.Contravariant) != 0)
AppendElementText(ce, "ParameterAttribute", "Contravariant");
if ((attrs & GenericParameterAttributes.Covariant) != 0)
AppendElementText(ce, "ParameterAttribute", "Covariant");
if ((attrs & GenericParameterAttributes.DefaultConstructorConstraint) != 0)
AppendElementText(ce, "ParameterAttribute", "DefaultConstructorConstraint");
if ((attrs & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
AppendElementText(ce, "ParameterAttribute", "NotNullableValueTypeConstraint");
if ((attrs & GenericParameterAttributes.ReferenceTypeConstraint) != 0)
AppendElementText(ce, "ParameterAttribute", "ReferenceTypeConstraint");
#if NEW_CECIL
foreach (GenericParameterConstraint c in constraints)
{
TypeDefinition cd = c.ConstraintType.Resolve ();
AppendElementText (ce,
(cd != null && cd.IsInterface) ? "InterfaceName" : "BaseTypeName",
GetDocTypeFullName (c.ConstraintType));
}
#else
foreach (TypeReference c in constraints)
{
TypeDefinition cd = c.Resolve();
AppendElementText(ce,
(cd != null && cd.IsInterface) ? "InterfaceName" : "BaseTypeName",
GetDocTypeFullName(c));
}
#endif
if (ce.HasChildNodes)
{
pe.AppendChild(ce);
}
}
internal static void ClearFrameworkAlternateIfAll(XmlElement element, string elementName, string allFrameworks)
{
if (element == null || string.IsNullOrEmpty(elementName) || string.IsNullOrEmpty(allFrameworks))
{
return;
}
var finalNodes = element.GetElementsByTagName(elementName).Cast<XmlElement>().ToArray();
foreach (var node in finalNodes)
{
// if FXAlternate is entire list, just remove it
if (node.HasAttribute(Consts.FrameworkAlternate) && node.GetAttribute(Consts.FrameworkAlternate) == allFrameworks)
{
node.RemoveAttribute(Consts.FrameworkAlternate);
}
}
// if there are no fx attributes left, just remove the indices entirely
if (!finalNodes.Any(n => n.HasAttribute(Consts.FrameworkAlternate)))
{
foreach (var node in finalNodes)
{
node.RemoveAttribute(Consts.Index);
}
}
}
internal static XmlElement AppendElementText(XmlNode parent, string element, string value)
{
XmlElement n = parent.OwnerDocument.CreateElement(element);
parent.AppendChild(n);
n.InnerText = value;
return n;
}
}
}
|