Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 522ab83

Browse files
committed
Improving class Position
1 parent e1cead5 commit 522ab83

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

Visual Studio Project Template C#/GatewayDomain.cs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,63 @@ public int Value
6060
/// If you use messages, there is nothing to stop you setting a position that is in the middle of a CRLF pair, or in the middle of a 2 byte character.
6161
/// However, keyboard commands will not move the caret into such positions.
6262
/// </summary>
63-
public class Position
63+
public class Position : IEquatable<Position>
6464
{
65-
private readonly int Pos;
65+
private readonly int pos;
6666

6767
public Position(int pos)
6868
{
69-
Pos = pos;
69+
this.pos = pos;
7070
}
7171

7272
public int Value
7373
{
74-
get { return Pos; }
74+
get { return pos; }
75+
}
76+
77+
public static Position operator +(Position a, Position b)
78+
{
79+
return new Position(a.pos + b.pos);
80+
}
81+
82+
public static Position operator -(Position a, Position b)
83+
{
84+
return new Position(a.pos - b.pos);
85+
}
86+
87+
public static bool operator ==(Position a, Position b)
88+
{
89+
return a.pos == b.pos;
90+
}
91+
92+
public static bool operator !=(Position a, Position b)
93+
{
94+
return !(a == b);
95+
}
96+
97+
public override string ToString()
98+
{
99+
return "Postion: " + pos;
100+
}
101+
102+
public bool Equals(Position other)
103+
{
104+
if (ReferenceEquals(null, other)) return false;
105+
if (ReferenceEquals(this, other)) return true;
106+
return pos == other.pos;
107+
}
108+
109+
public override bool Equals(object obj)
110+
{
111+
if (ReferenceEquals(null, obj)) return false;
112+
if (ReferenceEquals(this, obj)) return true;
113+
if (obj.GetType() != this.GetType()) return false;
114+
return Equals((Position)obj);
115+
}
116+
117+
public override int GetHashCode()
118+
{
119+
return pos;
75120
}
76121
}
77122

0 commit comments

Comments
 (0)