using System; using System.Collections; using System.Collections.Generic; namespace OpenVIII { public class BufferWithAge : IReadOnlyList { #region Fields private readonly byte[] _buffer; #endregion Fields #region Constructors public BufferWithAge(byte[] buffer) { this._buffer = buffer; Used = Created = DateTime.Now; } #endregion Constructors #region Properties public int Count => ((IReadOnlyList)_buffer).Count; public DateTime Created { get; } public DateTime Used { get; set; } #endregion Properties #region Indexers public byte this[int index] => ((IReadOnlyList)_buffer)[index]; #endregion Indexers #region Methods public static implicit operator BufferWithAge(byte[] @in) => new BufferWithAge(@in); public static implicit operator byte[] (BufferWithAge @in) => @in._buffer; public IEnumerator GetEnumerator() => ((IReadOnlyList)_buffer).GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => ((IReadOnlyList)_buffer).GetEnumerator(); public DateTime Poke() => Used = DateTime.Now; public override string ToString() => $"{{{nameof(Created)}: {Created}, {nameof(Used)}: {Used}, Size: {_buffer?.Length ?? 0}}}"; #endregion Methods } }