-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathDomNode.cs
More file actions
103 lines (86 loc) · 2.67 KB
/
Copy pathDomNode.cs
File metadata and controls
103 lines (86 loc) · 2.67 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
// Copyright © 2010-2017 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
namespace CefSharp
{
/// <summary>
/// Represents a node in the browser's DOM.
/// </summary>
public class DomNode : IDomNode
{
private readonly IDictionary<string, string> _attributes;
public DomNode (string tagName, IDictionary<string, string> attributes)
{
TagName = tagName;
_attributes = attributes;
}
public override string ToString ()
{
var sb = new StringBuilder ();
if (_attributes != null)
{
foreach (var pair in _attributes)
{
sb.AppendFormat ("{0}{1}:'{2}'", 0 < sb.Length ? ", " : String.Empty, pair.Key, pair.Value);
}
}
if (!String.IsNullOrWhiteSpace (TagName))
{
sb.Insert (0, String.Format ("{0} ", TagName));
}
if (sb.Length < 1)
{
return base.ToString ();
}
return sb.ToString ();
}
public string this[string name]
{
get
{
if (_attributes == null || _attributes.Count < 1 || !_attributes.ContainsKey (name))
{
return null;
}
return _attributes[name];
}
}
public string TagName { get; private set; }
public ReadOnlyCollection<string> AttributeNames
{
get
{
if (_attributes == null)
{
return new ReadOnlyCollection<string> (new List<string> ());
}
return Array.AsReadOnly<string> (_attributes.Keys.ToArray ());
}
}
public bool HasAttribute (string attributeName)
{
if (_attributes == null)
{
return false;
}
return _attributes.ContainsKey (attributeName);
}
public IEnumerator<KeyValuePair<string, string>>GetEnumerator()
{
if (_attributes == null)
{
return new Dictionary<string, string>().GetEnumerator();
}
return _attributes.GetEnumerator ();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator ();
}
}
}