-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityPath.cs
More file actions
124 lines (107 loc) · 3.85 KB
/
EntityPath.cs
File metadata and controls
124 lines (107 loc) · 3.85 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System.Collections.Generic;
namespace EntityCoding
{
/// <summary>
/// Describes the entity and property path used to reach this point in
/// the entity tree. This is basically just a helper class to provide some
/// extra methods we can use to simplify code.
/// </summary>
public class EntityPath : List<EntityPathComponent>
{
#region Instance Methods
/// <summary>
/// Create a duplicate copy of this entity path and return it.
/// </summary>
/// <returns>A duplicate of this entity path.</returns>
public EntityPath Clone()
{
EntityPath path = new EntityPath();
path.AddRange( this );
return path;
}
#endregion
#region Base Method Overrides
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <summary>
/// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals( object obj )
{
return base.Equals( obj );
}
/// <summary>
/// Implements the operator ==.
/// </summary>
/// <param name="a">The instance of this object that will be compared.</param>
/// <param name="b">The string instance we are comparing to.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static bool operator ==( EntityPath a, string b )
{
return ( a.ToString() == b );
}
/// <summary>
/// Implements the operator !=.
/// </summary>
/// <param name="a">The instance of this object that will be compared.</param>
/// <param name="b">The string instance we are comparing to.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static bool operator !=( EntityPath a, string b )
{
return !( a == b );
}
/// <summary>
/// Implements the operator +.
/// </summary>
/// <param name="a">The instance of this object that will is the left side of the operator.</param>
/// <param name="b">The EntityPathComponent instance that is the right side of the operator.</param>
/// <returns>
/// The result of the operator.
/// </returns>
public static EntityPath operator +( EntityPath a, EntityPathComponent b )
{
EntityPath path = a.Clone();
path.Add( b );
return path;
}
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
public override string ToString()
{
string value = string.Empty;
foreach ( var component in this )
{
if ( !string.IsNullOrEmpty( value ) )
{
value = value + "." + component.PropertyName;
}
else
{
value = component.PropertyName;
}
}
return value;
}
#endregion
}
}