Exemplo n.º 1
0
        /// <summary>
        /// Serializes an object
        /// </summary>
        /// <param name="writer">The target stream</param>
        /// <param name="instance">The object to serialize. This can be null.</param>
        /// <param name="flags">One or more <see cref="SerializedFlags"/> options</param>
        public static void Serialize <T>(IPrimitiveWriter writer, T instance, SerializerFlags flags)
        {
            TypeSerializationInfo typeInfo = TypeSerializationInfo.GetTypeInfo <T>(instance);
            TypeSerializationArgs args     = new TypeSerializationArgs();

            args.Writer = writer;
            args.Flags  = flags;

            typeInfo.Serialize(instance, args);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Internal use only
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="instance"></param>
        /// <param name="args"></param>
        public static void Serialize <T>(T instance, TypeSerializationArgs args)
        {
            TypeSerializationInfo typeInfo = null;

            if (args.IsBaseClass)
            {
                //  For base class handling, make sure we explicitly get the type
                //  info for the template parameter
                typeInfo = TypeSerializationInfo.GetTypeInfo(typeof(T));
            }
            else
            {
                //  Otherwise use the default type detection
                typeInfo = TypeSerializationInfo.GetTypeInfo <T>(instance);
            }

            typeInfo.Serialize(instance, args);
        }