-
Notifications
You must be signed in to change notification settings - Fork 6
/
Node.cs
70 lines (60 loc) · 1.44 KB
/
Node.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
// Non-nullable member is uninitialized
#pragma warning disable CS8618
// ReSharper disable All
using M31.FluentApi.Attributes;
namespace ExampleProject;
[FluentApi("CreateTree")]
public class Node<T>
{
private Node()
{
}
public Node(T value, Node<T>? left, Node<T>? right)
{
Value = value;
Left = left;
Right = right;
}
public T Value { get; private set; }
public Node<T>? Left { get; private set; }
public Node<T>? Right { get; private set; }
[FluentMethod(0)]
private void Root(T value)
{
Value = value;
}
[FluentMethod(1, "Left")]
private void SetLeftNode(T value, Func<CreateTree<T>.ILeftLeftNull, Node<T>>? createTree = null)
{
if (createTree == null)
{
Left = new Node<T>(value, null, null);
}
else
{
Left = createTree(CreateTree<T>.InitialStep().Root(value));
}
}
[FluentMethod(1)]
private void LeftNull()
{
Left = null;
}
[FluentMethod(2, "Right")]
private void SetRightNode(T value, Func<CreateTree<T>.ILeftLeftNull, Node<T>>? createTree = null)
{
if (createTree == null)
{
Right = new Node<T>(value, null, null);
}
else
{
Right = createTree(CreateTree<T>.InitialStep().Root(value));
}
}
[FluentMethod(2)]
private void RightNull()
{
Right = null;
}
}