public void SetData(byte[] data) { if (data != null) { bool changed = true; if (this._byteProvider != null && data.Length == this._byteProvider.Bytes.Count) { changed = false; for (int i = 0; i < this._byteProvider.Bytes.Count; i++) { if (this._byteProvider.Bytes[i] != data[i]) { changed = true; break; } } } if (changed) { bool needInit = _byteProvider == null; _byteProvider = new StaticByteProvider(data); _byteProvider.ByteChanged += (int byteIndex, byte newValue, byte oldValue) => { ByteChanged?.Invoke(byteIndex, newValue, oldValue); }; this.ctrlHexBox.ByteProvider = _byteProvider; if (needInit) { InitializeContextMenu?.Invoke(this.ctrlHexBox, EventArgs.Empty); } } } }
/// <summary> /// Write a byte into the byte collection. /// </summary> /// <param name="index">the index of the byte to write.</param> /// <param name="value">the byte</param> public void WriteByte(long index, byte value) { if (_bytes[(int)index] != value) { ByteChanged?.Invoke((int)index, value, _bytes[(int)index]); _bytes[(int)index] = value; OnChanged(EventArgs.Empty); } }