Files
MicrosoftIris/UIX/Microsoft/Iris/Debug/Data/Breakpoint.cs
T

80 lines
2.0 KiB
C#
Raw Normal View History

2023-05-29 20:19:14 -05:00
using System;
using System.Text;
namespace Microsoft.Iris.Debug.Data;
2023-06-02 00:08:28 -05:00
[Serializable]
2023-05-29 20:19:14 -05:00
public struct Breakpoint : IEquatable<Breakpoint>
{
public Breakpoint(string uri, int line, int column, bool enabled = true) : this(uri, enabled)
{
Line = line;
Column = column;
}
public Breakpoint(string uri, uint offset, bool enabled = true) : this(uri, enabled)
{
Offset = offset;
}
private Breakpoint(string uri, bool enabled)
{
Uri = uri;
Enabled = enabled;
}
public string Uri { get; set; }
public int Line { get; set; } = -1;
public int Column { get; set; } = -1;
public uint Offset { get; set; } = uint.MaxValue;
public bool Enabled { get; set; }
2023-06-02 00:08:28 -05:00
public bool Equals(string uri, int line, int column, uint offset = uint.MaxValue)
{
if (!Uri.Equals(uri, StringComparison.OrdinalIgnoreCase))
return false;
if (Offset != uint.MaxValue && offset != uint.MaxValue)
return Offset == offset;
else
return line == Line && column == Column;
}
2023-05-29 20:19:14 -05:00
public bool Equals(Breakpoint other) => Equals(other.Uri, other.Line, other.Column);
public static bool operator ==(Breakpoint left, Breakpoint right) => left.Equals(right);
public static bool operator !=(Breakpoint left, Breakpoint right) => !(left == right);
public override bool Equals(object obj) => obj is Breakpoint bp && Equals(bp);
2024-01-20 20:32:30 -06:00
public override string ToString() => ToString(true);
public string ToString(bool includeEnabled)
2023-05-29 20:19:14 -05:00
{
StringBuilder sb = new();
2024-01-20 20:32:30 -06:00
if (includeEnabled)
{
sb.Append(Enabled ? '+' : '-');
sb.Append(' ');
}
2023-05-29 20:19:14 -05:00
sb.Append(Uri);
sb.Append(' ');
if (Line >= 0 && Column >= 0)
sb.Append($"({Line}, {Column})");
else
sb.Append($"0x{Offset:X}");
return sb.ToString();
}
2024-01-20 20:32:30 -06:00
public override int GetHashCode() => ToString(false).GetHashCode();
2023-05-29 20:19:14 -05:00
}