using System; namespace ScreenConnect; [Serializable] public struct Utf8String : IComparable, IComparable, IEquatable { private byte[]? buffer; private string? @string; public byte[] Buffer => buffer ?? (buffer = Constants.UTF8EncodingWithoutPreamble.GetBytes(@string ?? (@string = string.Empty))); public string String => @string ?? (@string = Constants.UTF8EncodingWithoutPreamble.GetString(buffer ?? (buffer = Extensions.EmptyArray()))); public Utf8String(byte[]? buffer) { this.buffer = buffer; @string = null; } public Utf8String(string? @string) { this.@string = @string; buffer = null; } public static Utf8String FromBuffer(byte[]? buffer) { return new Utf8String(buffer); } public static Utf8String FromString(string? @string) { return new Utf8String(@string); } public override string ToString() { return String; } public static implicit operator string(Utf8String @this) { return @this.String; } public static implicit operator Utf8String(string? @this) { return FromString(@this); } public static bool operator ==(Utf8String x, Utf8String y) { return object.Equals(x, y); } public static bool operator !=(Utf8String x, Utf8String y) { return !object.Equals(x, y); } public override int GetHashCode() { return String.GetHashCode(); } public int CompareTo(object? other) { if (other != null) { if (other is Utf8String other2) { return CompareTo(other2); } throw new ArgumentException(); } return 1; } public int CompareTo(Utf8String other) { return String.CompareTo(other.String); } public override bool Equals(object? other) { if (other is Utf8String other2) { return Equals(other2); } return false; } public bool Equals(Utf8String other) { return String.Equals(other.String); } public bool Equals(string other) { return String.Equals(other); } }