Example #1
0
        public IlBasedSerializers()
        {
            // Configure the serializer to be used when a concrete type is not known.
            // The serializer will generate and register serializers for concrete types
            // as they are discovered.
            this.genericSerializer = new GeneratedSerializer(
                original =>
            {
                if (original == null)
                {
                    return(null);
                }

                return(this.GetAndRegister(original.GetType()).DeepCopy(original));
            },
                (original, writer, expected) =>
            {
                if (original == null)
                {
                    writer.WriteNull();
                    return;
                }

                this.GetAndRegister(original.GetType()).Serialize(original, writer, expected);
            },
                (expected, reader) => this.GetAndRegister(expected).Deserialize(expected, reader));

            this.typeSerializer = new GeneratedSerializer(
                original => original,
                (original, writer, expected) => { writer.Write(((Type)original).AssemblyQualifiedName); },
                (expected, reader) => Type.GetType(reader.ReadString(), throwOnError: true));
        }
Example #2
0
        public IlBasedSerializers()
        {
            // Configure the serializer to be used when a concrete type is not known.
            // The serializer will generate and register serializers for concrete types
            // as they are discovered.
            this.genericSerializer = new GeneratedSerializer(
                original =>
                {
                    if (original == null)
                    {
                        return null;
                    }

                    return this.GetAndRegister(original.GetType()).DeepCopy(original);
                },
                (original, writer, expected) =>
                {
                    if (original == null)
                    {
                        writer.WriteNull();
                        return;
                    }

                    this.GetAndRegister(original.GetType()).Serialize(original, writer, expected);
                },
                (expected, reader) => this.GetAndRegister(expected).Deserialize(expected, reader));

            this.typeSerializer = new GeneratedSerializer(
                original => original,
                (original, writer, expected) => { writer.Write(((Type)original).AssemblyQualifiedName); },
                (expected, reader) => Type.GetType(reader.ReadString(), throwOnError: true));
        }
Example #3
0
        public ILBasedSerializer()
        {
            this.exceptionFieldFilter = ExceptionFieldFilter;

            // Configure the serializer to be used when a concrete type is not known.
            // The serializer will generate and register serializers for concrete types
            // as they are discovered.
            this.thisSerializer = new SerializationManager.SerializerMethods(
                this.DeepCopy,
                this.Serialize,
                this.Deserialize);

            this.typeSerializer = new SerializerBundle(
                typeof(Type),
                new SerializationManager.SerializerMethods(
                    original => original,
                    (original, writer, expected) => { this.WriteNamedType((Type)original, writer); },
                    (expected, reader) => this.ReadNamedType(reader)));
            this.generateSerializer = this.GenerateSerializer;
        }
Example #4
0
        public ILBasedExceptionSerializer(ILSerializerGenerator generator, TypeSerializer typeSerializer)
        {
            this.generator      = generator;
            this.typeSerializer = typeSerializer;

            // Exceptions are a special type in .NET because of the way they are handled by the runtime.
            // Only certain fields can be safely serialized.
            this.exceptionFieldFilter = field =>
            {
                // Any field defined below Exception is acceptable.
                if (field.DeclaringType != ExceptionType)
                {
                    return(true);
                }

                // Certain fields from the Exception base class are acceptable.
                return(field.FieldType == typeof(string) || field.FieldType == ExceptionType);
            };

            // When serializing the fallback type, only the fields declared on Exception are included.
            // Other fields are manually serialized.
            this.fallbackBaseExceptionSerializer = this.generator.GenerateSerializer(
                typeof(RemoteNonDeserializableException),
                field =>
            {
                // Only serialize base-class fields.
                if (field.DeclaringType != ExceptionType)
                {
                    return(false);
                }

                // Certain fields from the Exception base class are acceptable.
                return(field.FieldType == typeof(string) || field.FieldType == ExceptionType);
            },
                fieldComparer: ExceptionFieldInfoComparer.Instance);

            // Ensure that the fallback serializer only ever has its base exception fields serialized.
            this.serializers[typeof(RemoteNonDeserializableException)] = this.fallbackBaseExceptionSerializer;
        }
Example #5
0
 public SerializerBundle(SerializationManager.SerializerMethods methods)
 {
     this.Methods = methods;
 }
Example #6
0
 public SerializerBundle(Type type, SerializationManager.SerializerMethods methods)
 {
     this.Type    = type;
     this.Methods = methods;
 }