Beispiel #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);
        }
Beispiel #2
0
        public static bool Compare <T>(T x, T y)
        {
            Type t = ((object)x).GetType();

            if (t != ((object)y).GetType())
            {
                return(false);
            }

            return(TypeSerializationInfo.GetTypeInfo <T>(x).Compare(x, y));
        }
Beispiel #3
0
        public static object Deserialize(Stream stream, SerializerFlags flags, CompressionImplementation compression, Type instanceType)
        {
            TypeSerializationInfo typeInfo = null;
            TypeSerializationArgs args     = new TypeSerializationArgs();
            object instance = Activator.CreateInstance(instanceType);

            args.Flags  = flags;
            args.Reader = GetReader(stream, flags, compression);

            typeInfo = TypeSerializationInfo.GetTypeInfo(instanceType);
            typeInfo.Deserialize(ref instance, args);

            return(instance);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        /// <summary>
        /// Internal use only
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="instance"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static bool Deserialize <T>(ref object instance, TypeSerializationArgs args)
        {
            TypeSerializationInfo typeInfo = null;

            //  Check arguments
            if (args.Reader == null)
            {
                Debug.Fail("Input stream is null");
                throw new ArgumentNullException("reader");
            }

            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);
            }
            return(typeInfo.Deserialize(ref instance, args));
        }
Beispiel #6
0
 public static void CallGetTypeInfo <T>(object instance)
 {
     TypeSerializationInfo.GetTypeInfo <T>(instance);
 }