Exemplo n.º 1
0
        /// <summary>
        /// Serializes an object into the specified compact binary writer.
        /// </summary>
        /// <param name="writer">specified compact binary writer</param>
        /// <param name="graph">object</param>
        static internal void Serialize(CompactBinaryWriter writer, object graph, string cacheContext)
        {
            // Find an appropriate surrogate for the object
            ISerializationSurrogate surrogate =
                TypeSurrogateSelector.GetSurrogateForObject(graph, cacheContext);

            // write type handle
            writer.Context.CacheContext = cacheContext;
            writer.Write(surrogate.TypeHandle);
            surrogate.Write(writer, graph);
        }
Exemplo n.º 2
0
        public override void WriteObjectAs <T>(T graph)
        {
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }

            // Find an appropriate surrogate for the object
            ISerializationSurrogate surrogate = TypeSurrogateSelector.GetSurrogateForType(typeof(T), context.CacheContext);

            surrogate.Write(this, graph);
        }
        public override void Write(CompactBinaryWriter writer, object graph)
        {
            ISerializationSurrogate surrogateForType = TypeSurrogateSelector.GetSurrogateForType(typeof(T), null);

            T?[] nullableArray = (T?[])graph;
            writer.Write(surrogateForType.TypeHandle);
            writer.Write(nullableArray.Length);
            for (int i = 0; i < nullableArray.Length; i++)
            {
                if (nullableArray[i].HasValue)
                {
                    writer.Write(i);
                    surrogateForType.Write(writer, nullableArray[i].Value);
                }
            }
            writer.Write(-1);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="graph"></param>
        public override void WriteObject(object graph)
        {
            ISerializationSurrogate surrogateForObject = TypeSurrogateSelector.GetSurrogateForObject(graph, _context.CacheContext);

            _writer.Write(surrogateForObject.TypeHandle);
            try
            {
                surrogateForObject.Write(this, graph);
            }
            catch (CompactSerializationException)
            {
                throw;
            }
            catch (Exception exception)
            {
                throw new CompactSerializationException(exception.Message);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Writes <paramref name="graph"/> to the current stream and advances the stream position.
        /// </summary>
        /// <param name="graph">Object to write</param>
        public override void WriteObject(object graph)
        {
            //Console.WriteLine(graph);

            // Find an appropriate surrogate for the object
            ISerializationSurrogate surrogate = TypeSurrogateSelector.GetSurrogateForObject(graph, context.CacheContext);

            // write type handle
            writer.Write(surrogate.TypeHandle);
            try
            {
                surrogate.Write(this, graph);
            }
            catch (CompactSerializationException)
            {
                throw;
            }
            catch (System.Threading.ThreadAbortException)
            {
                throw;
            }
            catch (System.Threading.ThreadInterruptedException)
            {
                throw;
            }
            catch (System.Runtime.Serialization.SerializationException ex)
            {
                if (ex.Message.Contains("is not marked as serializable"))
                {
                    throw new CompactSerializationException(graph.GetType().FullName + " is not marked as serializable.", ex);
                }
                else
                {
                    throw new CompactSerializationException(ex.Message);
                }
            }
            catch (Exception e)
            {
                //Trace.error("CompactBinaryWriter.WriteObject", "type: " + surrogate.ActualType + " handle: " + surrogate.TypeHandle
                //    + "exception : " + e);
                throw new CompactSerializationException(e.Message);
            }
        }
Exemplo n.º 6
0
        public override void Write(CompactBinaryWriter writer, object graph)
        {
            // Find an appropriate surrogate for the object
            ISerializationSurrogate typeSurr = TypeSurrogateSelector.GetSurrogateForType(typeof(T), null);

            T?[] array = (T?[])graph;

            // write type handle
            writer.Write(typeSurr.TypeHandle);
            writer.Write(array.Length);
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i].HasValue)
                {
                    writer.Write(i);
                    typeSurr.Write(writer, array[i].Value);
                }
            }
            writer.Write(-1);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Writes <paramref name="graph"/> to the current stream and advances the stream position.
        /// </summary>
        /// <param name="graph">Object to write</param>
        public override void WriteObject(object graph)
        {
            // Find an appropriate surrogate for the object
            ISerializationSurrogate surrogate = TypeSurrogateSelector.GetSurrogateForObject(graph, context.CacheContext);

            // write type handle
            writer.Write(surrogate.TypeHandle);
            try
            {
                surrogate.Write(this, graph);
            }
            catch (CompactSerializationException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new CompactSerializationException(e.Message);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Writes <paramref name="graph"/> to the current stream and advances the stream position.
        /// </summary>
        /// <param name="graph">Object to write</param>
        public override void WriteObject(object graph)
        {
            //Console.WriteLine(graph);

            // Find an appropriate surrogate for the object
            ISerializationSurrogate surrogate = TypeSurrogateSelector.GetSurrogateForObject(graph, context.CacheContext);

            // write type handle
            writer.Write(surrogate.TypeHandle);
            try
            {
                surrogate.Write(this, graph);
            }
            catch (CompactSerializationException)
            {
                throw;
            }
            catch (Exception e)
            {
                //Trace.error("CompactBinaryWriter.WriteObject", "type: " + surrogate.ActualType + " handle: " + surrogate.TypeHandle
                //    + "exception : " + e);
                throw new CompactSerializationException(e.Message);
            }
        }