-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlElement.cs
More file actions
60 lines (52 loc) · 1.53 KB
/
HtmlElement.cs
File metadata and controls
60 lines (52 loc) · 1.53 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HtmlSerializer
{
public class HtmlAttribute
{
public string Name { get; set; }
public string Value { get; set; }
}
public class HtmlElement
{
public string Id { get; set; }
public string Name { get; set; }
public List<HtmlAttribute> Attributes { get; set; } = new();
public List<string> Classes { get; set; } = new();
public string InnerHtml { get; set; } = "";
public HtmlElement Parent { get; set; }
public List<HtmlElement> Children { get; set; } = new();
// פונקציה להוספת ילד
public void AddChild(HtmlElement child)
{
child.Parent = this;
Children.Add(child);
}
public IEnumerable<HtmlElement> Descendants()
{
var queue=new Queue<HtmlElement>();
queue.Enqueue(this);
while (queue.Count > 0)
{
var current= queue.Dequeue();
yield return current;
foreach (var child in current.Children)
{
queue.Enqueue(child);
}
}
}
public IEnumerable<HtmlElement> Ancestors()
{
var current = this.Parent;
while(current != null)
{
yield return current;
current = current.Parent;
}
}
}
}