/** <inheritdoc /> */ public override bool Equals(object obj) { if (this == obj) { return(true); } PortableUserObject that = obj as PortableUserObject; if (that != null) { if (_data == that._data && _offset == that._offset) { return(true); } // 1. Check hash code and type IDs. if (_hashCode == that._hashCode && _typeId == that._typeId) { // 2. Check if objects have the same field sets. InitializeFields(); that.InitializeFields(); if (_fields.Keys.Count != that._fields.Keys.Count) { return(false); } foreach (int id in _fields.Keys) { if (!that._fields.Keys.Contains(id)) { return(false); } } // 3. Check if objects have the same field values. foreach (KeyValuePair <int, int> field in _fields) { object fieldVal = Field0 <object>(field.Value, null); object thatFieldVal = that.Field0 <object>(that._fields[field.Key], null); if (!Equals(fieldVal, thatFieldVal)) { return(false); } } // 4. Check if objects have the same raw data. IPortableStream stream = new PortableHeapStream(_data); stream.Seek(_offset + 10, SeekOrigin.Begin); int len = stream.ReadInt(); int rawOffset = stream.ReadInt(); IPortableStream thatStream = new PortableHeapStream(that._data); thatStream.Seek(_offset + 10, SeekOrigin.Begin); int thatLen = thatStream.ReadInt(); int thatRawOffset = thatStream.ReadInt(); return(PortableUtils.CompareArrays(_data, _offset + rawOffset, len - rawOffset, that._data, that._offset + thatRawOffset, thatLen - thatRawOffset)); } } return(false); }