Exemple #1
0
        /// <summary>
        /// Provides the actual implementation for serializing a value of type <see cref="T" />.
        /// </summary>
        /// <param name="value">The value to serialize.</param>
        /// <param name="writer">The writer to serialize with.</param>
        protected override void SerializeImplementation(ref T[] value, IDataWriter writer)
        {
            try
            {
                writer.BeginArrayNode(value.Length);

                for (int i = 0; i < value.Length; i++)
                {
                    valueReaderWriter.WriteValue(value[i], writer);
                }
            }
            finally
            {
                writer.EndArrayNode();
            }
        }
        /// <summary>
        /// Provides the actual implementation for serializing a value of type <see cref="T" />.
        /// </summary>
        /// <param name="value">The value to serialize.</param>
        /// <param name="writer">The writer to serialize with.</param>
        protected override void SerializeImplementation(ref Dictionary <TKey, TValue> value, IDataWriter writer)
        {
            try
            {
                if (value.Comparer != null)
                {
                    EqualityComparerSerializer.WriteValue("comparer", value.Comparer, writer);
                }

                writer.BeginArrayNode(value.Count);

                foreach (var pair in value)
                {
                    bool endNode = true;

                    try
                    {
                        writer.BeginStructNode(null, null);
                        KeyReaderWriter.WriteValue("$k", pair.Key, writer);
                        ValueReaderWriter.WriteValue("$v", pair.Value, writer);
                    }
                    catch (SerializationAbortException ex)
                    {
                        endNode = false;
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        writer.Context.Config.DebugContext.LogException(ex);
                    }
                    finally
                    {
                        if (endNode)
                        {
                            writer.EndNode(null);
                        }
                    }
                }
            }
            finally
            {
                writer.EndArrayNode();
            }
        }
Exemple #3
0
        /// <summary>
        /// Provides the actual implementation for serializing a value of type <see cref="T" />.
        /// </summary>
        /// <param name="value">The value to serialize.</param>
        /// <param name="writer">The writer to serialize with.</param>
        protected override void SerializeImplementation(ref TArray value, IDataWriter writer)
        {
            var array = value as Array;

            try
            {
                writer.BeginArrayNode(array.LongLength);

                int[] lengths = new int[ArrayRank];

                for (int i = 0; i < ArrayRank; i++)
                {
                    lengths[i] = array.GetLength(i);
                }

                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < ArrayRank; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(RANKS_SEPARATOR);
                    }

                    sb.Append(lengths[i].ToString(CultureInfo.InvariantCulture));
                }

                string lengthStr = sb.ToString();

                writer.WriteString(RANKS_NAME, lengthStr);

                this.IterateArrayRead(
                    (Array)(object)value,
                    (v) =>
                {
                    ValueReaderWriter.WriteValue(v, writer);
                });
            }
            finally
            {
                writer.EndArrayNode();
            }
        }
        protected override void Write(ref AotDictionary dictionary, IDataWriter writer)
        {
            writer.BeginArrayNode(dictionary.Count);

            var keys = new object[dictionary.Keys.Count];

            dictionary.Keys.CopyTo(keys, 0);

            for (int i = 0; i < dictionary.Count; i++)
            {
                var key   = keys[i];
                var value = dictionary[i];

                ObjectSerializer.WriteValue(key, writer);
                ObjectSerializer.WriteValue(value, writer);
            }

            writer.EndArrayNode();
        }
        /// <summary>
        /// Serialization implementation.
        /// </summary>
        /// <param name="value">The value to serialize.</param>
        /// <param name="writer">The writer to write to.</param>
        protected override void SerializeImplementation(ref IndexedDictionary <TKey, TValue> value, IDataWriter writer)
        {
            try
            {
                writer.BeginArrayNode(value.Count);

                bool endNode = true;

                for (int i = 0; i < value.Count; i++)
                {
                    var entry = value.Get(i);

                    try
                    {
                        writer.BeginStructNode(null, null);
                        KeyReaderWriter.WriteValue(entry.Key, writer);
                        ValueReaderWriter.WriteValue(entry.Value, writer);
                    }
                    catch (SerializationAbortException ex)
                    {
                        endNode = false;
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        writer.Context.Config.DebugContext.LogException(ex);
                    }
                    finally
                    {
                        if (endNode)
                        {
                            writer.EndNode(null);
                        }
                    }
                }
            }
            finally
            {
                writer.EndArrayNode();
            }
        }
Exemple #6
0
        /// <summary>
        /// Provides the actual implementation for serializing a value of type <see cref="!:T" />.
        /// </summary>
        /// <param name="value">The value to serialize.</param>
        /// <param name="writer">The writer to serialize with.</param>
        protected override void SerializeImplementation(ref DoubleLookupDictionary <TPrimary, TSecondary, TValue> value, IDataWriter writer)
        {
            try
            {
                writer.BeginArrayNode(value.Count);

                bool endNode = true;

                foreach (var pair in value)
                {
                    try
                    {
                        writer.BeginStructNode(null, null);
                        PrimaryReaderWriter.WriteValue("$k", pair.Key, writer);
                        InnerReaderWriter.WriteValue("$v", pair.Value, writer);
                    }
                    catch (SerializationAbortException ex)
                    {
                        endNode = false;
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        writer.Context.Config.DebugContext.LogException(ex);
                    }
                    finally
                    {
                        if (endNode)
                        {
                            writer.EndNode(null);
                        }
                    }
                }
            }
            finally
            {
                writer.EndArrayNode();
            }
        }
        /// <summary>
        /// Provides the actual implementation for serializing a value of type <see cref="T" />.
        /// </summary>
        /// <param name="value">The value to serialize.</param>
        /// <param name="writer">The writer to serialize with.</param>
        protected override void SerializeImplementation(ref HashSet <T> value, IDataWriter writer)
        {
            try
            {
                writer.BeginArrayNode(value.Count);

                foreach (T item in value)
                {
                    try
                    {
                        TSerializer.WriteValue(item, writer);
                    }
                    catch (Exception ex)
                    {
                        writer.Context.Config.DebugContext.LogException(ex);
                    }
                }
            }
            finally
            {
                writer.EndArrayNode();
            }
        }
Exemple #8
0
        /// <summary>
        /// Provides the actual implementation for serializing a value of type <see cref="T" />.
        /// </summary>
        /// <param name="value">The value to serialize.</param>
        /// <param name="writer">The writer to serialize with.</param>
        protected override void SerializeImplementation(ref ArrayList value, IDataWriter writer)
        {
            try
            {
                writer.BeginArrayNode(value.Count);

                for (int i = 0; i < value.Count; i++)
                {
                    try
                    {
                        ObjectSerializer.WriteValue(value[i], writer);
                    }
                    catch (Exception ex)
                    {
                        writer.Context.Config.DebugContext.LogException(ex);
                    }
                }
            }
            finally
            {
                writer.EndArrayNode();
            }
        }