예제 #1
0
        /// <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));
        }
예제 #2
0
파일: Binary.cs 프로젝트: zshamrock/ignite
        /** <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));
            }
        }