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; }
public SerializerBundle(SerializerMethods methods) { this.Methods = methods; }