/// <summary> /// Gets field value on the given object. /// </summary> /// <param name="pos">Position.</param> /// <param name="builder">Builder.</param> /// <returns>Field value.</returns> public T GetField <T>(int pos, BinaryObjectBuilder builder) { IBinaryStream stream = new BinaryHeapStream(_data); stream.Seek(pos + _offset, SeekOrigin.Begin); return(_marsh.Unmarshal <T>(stream, BinaryMode.ForceBinary, builder)); }
/** <inheritDoc /> */ public T ToBinary <T>(object obj) { if (obj is IBinaryObject) { return((T)obj); } using (var stream = new BinaryHeapStream(1024)) { // Serialize. BinaryWriter writer = _marsh.StartMarshal(stream); try { writer.Write(obj); } finally { // Save metadata. _marsh.FinishMarshal(writer); } // Deserialize. stream.Seek(0, SeekOrigin.Begin); return(_marsh.Unmarshal <T>(stream, BinaryMode.ForceBinary)); } }