/
CharacterRange.cs
50 lines (40 loc) · 1.87 KB
/
CharacterRange.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace System.Drawing
{
[StructLayout(LayoutKind.Sequential)]
public struct CharacterRange : IEquatable<CharacterRange>
{
private int _first;
private int _length;
/// <summary>Initializes a new instance of the <see cref='CharacterRange'/> class with the specified coordinates.</summary>
public CharacterRange(int First, int Length)
{
_first = First;
_length = Length;
}
/// <summary>Gets the First character position of this <see cref='CharacterRange'/>.</summary>
public int First
{
get => _first;
set => _first = value;
}
/// <summary>Gets the Length of this <see cref='CharacterRange'/>.</summary>
public int Length
{
get => _length;
set => _length = value;
}
public override bool Equals([NotNullWhen(true)] object? obj) =>
obj is CharacterRange other && Equals(other);
/// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
/// <param name="other">An instance to compare with this instance.</param>
/// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
public bool Equals(CharacterRange other) => First == other.First && Length == other.Length;
public static bool operator ==(CharacterRange cr1, CharacterRange cr2) => cr1.Equals(cr2);
public static bool operator !=(CharacterRange cr1, CharacterRange cr2) => !cr1.Equals(cr2);
public override int GetHashCode() => HashCode.Combine(First, Length);
}
}