-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathCustomXmlElement.cs
90 lines (78 loc) · 2.54 KB
/
CustomXmlElement.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
using System.Collections.Generic;
using System.Xml;
namespace Multiplayer.Client
{
public class CustomXmlElement : XmlElement
{
public object val;
public int nodes;
public Dictionary<string, XmlNode> nodeDict;
public bool usedOutside = true;
public static long n;
public static long m;
public override XmlElement this[string name]
{
get
{
m++;
if (nodeDict != null)
{
n++;
nodeDict.TryGetValue(name, out XmlNode value);
return value as XmlElement;
}
for (XmlNode xmlNode = FirstChild; xmlNode != null; xmlNode = xmlNode.NextSibling)
{
n++;
if (xmlNode.NodeType == XmlNodeType.Element && xmlNode.Name == name)
{
return (XmlElement)xmlNode;
}
}
return null;
}
}
public CustomXmlElement(string prefix, string localName, string namespaceURI, XmlDocument doc): base(prefix, localName, namespaceURI, doc)
{
}
public override XmlNode AppendChild(XmlNode newChild)
{
XmlNode result = base.AppendChild(newChild);
if (!usedOutside)
{
nodes++;
if (nodeDict != null)
{
nodeDict[newChild.Name] = newChild;
}
if (nodes == 4)
{
nodeDict = new Dictionary<string, XmlNode>();
for (XmlNode xmlNode = FirstChild; xmlNode != null; xmlNode = xmlNode.NextSibling)
{
nodeDict[xmlNode.Name] = xmlNode;
}
}
}
return result;
}
public override XmlNode RemoveChild(XmlNode oldChild)
{
usedOutside = true;
nodeDict = null;
return base.RemoveChild(oldChild);
}
public override XmlNode InsertAfter(XmlNode newChild, XmlNode refChild)
{
usedOutside = true;
nodeDict = null;
return base.InsertAfter(newChild, refChild);
}
public override XmlNode InsertBefore(XmlNode newChild, XmlNode refChild)
{
usedOutside = true;
nodeDict = null;
return base.InsertBefore(newChild, refChild);
}
}
}