using CommunityToolkit.Mvvm.ComponentModel; using MultiTerm.Protocols.Model; namespace MultiTerm.Core.ViewModel; public partial class ByteDataViewModel : ObservableObject, IDataViewModel, IComparable, ICloneable { /// /// Object of data model. /// internal readonly ExtendedByte Data; #region IDataViewModel Implementation [ObservableProperty] private int lineIdentifier; [ObservableProperty] private string timeAsString = String.Empty; [ObservableProperty] private string displayStringChar = String.Empty; [ObservableProperty] private string displayStringHex = String.Empty; [ObservableProperty] private string displayStringBin = String.Empty; #endregion /// /// Instanciates new . /// Initializes internal variables with data according to . /// /// data /// identifies line in which this byte is located public ByteDataViewModel(ExtendedByte extendedByte, int lineIdentifier) { this.Data = extendedByte; this.lineIdentifier = lineIdentifier; this.DisplayStringChar = extendedByte.ToCharacterString(); this.DisplayStringHex = extendedByte.ToHexString(); this.DisplayStringBin = extendedByte.ToBinaryString(); this.TimeAsString = extendedByte.Time.ToString("HH:mm:ss.ffff"); } #region IComparable Implementation /// /// IComparable method. To allow sorting /// /// compared element /// public int CompareTo(ByteDataViewModel? other) { if(other == null) return 1; if (other.Data.Time.Ticks > this.Data.Time.Ticks) return -1; else if(this.Data.Time.Ticks > other.Data.Time.Ticks) return 1; else // equal return 0; } #endregion #region ICloneable Implementation public object Clone() { return this.MemberwiseClone(); } #endregion }