internal XmlObjectSerializerReadContextComplex(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver) : base(serializer, rootTypeDataContract, dataContractResolver) { _mode = SerializationMode.SharedContract; _preserveObjectReferences = serializer.PreserveObjectReferences; _serializationSurrogateProvider = serializer.SerializationSurrogateProvider; }
internal XmlObjectSerializerWriteContextComplex(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver) : base(serializer, rootTypeDataContract, dataContractResolver) { _mode = SerializationMode.SharedContract; this.preserveObjectReferences = serializer.PreserveObjectReferences; _serializationSurrogateProvider = serializer.SerializationSurrogateProvider; }
internal static Type GetDataContractType(ISerializationSurrogateProvider surrogateProvider, Type type) { if (DataContract.GetBuiltInDataContract(type) != null) { return(type); } return(surrogateProvider.GetSurrogateType(type) ?? type); }
internal static object GetDeserializedObject(ISerializationSurrogateProvider surrogateProvider, object obj, Type objType, Type memberType) { if (obj == null) return null; if (DataContract.GetBuiltInDataContract(objType) != null) return obj; return surrogateProvider.GetDeserializedObject(obj, memberType); }
internal static object?SurrogateToDataContractType(ISerializationSurrogateProvider serializationSurrogateProvider, object?oldObj, Type surrogatedDeclaredType, ref Type objType) { object?obj = DataContractSurrogateCaller.GetObjectToSerialize(serializationSurrogateProvider, oldObj, objType, surrogatedDeclaredType); if (obj != oldObj) { objType = obj != null?obj.GetType() : Globals.TypeOfObject; } return(obj); }
public static void SetSerializationSurrogateProvider(this DataContractSerializer serializer, ISerializationSurrogateProvider provider) { // allocate every time, expectation is that this won't happen enough to warrant maintaining a CondtionalWeakTable. IDataContractSurrogate adapter = new SurrogateProviderAdapter(provider); // DCS doesn't expose a setter, access the field directly as a workaround typeof(DataContractSerializer) .GetField("dataContractSurrogate", BindingFlags.Instance | BindingFlags.NonPublic) .SetValue(serializer, adapter); }
internal static object GetDeserializedObject(ISerializationSurrogateProvider surrogateProvider, object obj, Type objType, Type memberType) { if (obj == null) { return(null); } if (DataContract.GetBuiltInDataContract(objType) != null) { return(obj); } return(surrogateProvider.GetDeserializedObject(obj, memberType)); }
public void SurrogateProvider_Negative(Type badType, ISerializationSurrogateProvider surrogate, Type exceptionType, string exMsg = null) { XsdDataContractExporter exporter = new XsdDataContractExporter(); exporter.Options = new ExportOptions(); exporter.Options.DataContractSurrogate = surrogate; var ex = Assert.Throws(exceptionType, () => exporter.Export(badType)); if (exMsg != null) { Assert.Equal(exMsg, ex.Message); } }
public void SurrogateProvider(Type type, ISerializationSurrogateProvider surrogate, Action <string, XmlSchemaSet> schemaCheck = null) { ExportOptions options = new ExportOptions() { DataContractSurrogate = surrogate }; XsdDataContractExporter exporter = new XsdDataContractExporter() { Options = options }; exporter.Export(type); string schema = SchemaUtils.DumpSchema(exporter.Schemas); _output.WriteLine(schema); if (schemaCheck != null) { schemaCheck(schema, exporter.Schemas); } }
public SurrogateProviderAdapter(ISerializationSurrogateProvider provider) { _provider = provider; }
public static void SetSerializationSurrogateProvider(this DataContractSerializer serializer, ISerializationSurrogateProvider provider) { // allocate every time, expectation is that this won't happen enough to warrant maintaining a CondtionalWeakTable. IDataContractSurrogate adapter = new SurrogateProviderAdapter(provider); // DCS doesn't expose a setter, access the field directly as a workaround typeof(DataContractSerializer) .GetField("dataContractSurrogate", BindingFlags.Instance | BindingFlags.NonPublic) .SetValue(serializer, adapter); }
internal static Type GetDataContractType(ISerializationSurrogateProvider surrogateProvider, Type type) { if (DataContract.GetBuiltInDataContract(type) != null) return type; return surrogateProvider.GetSurrogateType(type) ?? type; }
public static void SetSerializationSurrogateProvider(this DataContractSerializer serializer, ISerializationSurrogateProvider provider) { serializer.SerializationSurrogateProvider = provider; }
internal static Type GetSurrogatedType(ISerializationSurrogateProvider serializationSurrogateProvider, Type type) { return DataContractSurrogateCaller.GetDataContractType(serializationSurrogateProvider, DataContract.UnwrapNullableType(type)); }
internal static object SurrogateToDataContractType(ISerializationSurrogateProvider serializationSurrogateProvider, object oldObj, Type surrogatedDeclaredType, ref Type objType) { object obj = DataContractSurrogateCaller.GetObjectToSerialize(serializationSurrogateProvider, oldObj, objType, surrogatedDeclaredType); if (obj != oldObj) { objType = obj != null ? obj.GetType() : Globals.TypeOfObject; } return obj; }
internal static Type GetSurrogatedType(ISerializationSurrogateProvider serializationSurrogateProvider, Type type) { return(DataContractSurrogateCaller.GetDataContractType(serializationSurrogateProvider, DataContract.UnwrapNullableType(type))); }
public static void SetSerializationSurrogateProvider(this DataContractSerializer serializer, ISerializationSurrogateProvider provider) { // allocate every time, expectation is that this won't happen enough to warrant maintaining a CondtionalWeakTable. IDataContractSurrogate adapter = new SurrogateProviderAdapter(provider); serializer.SetDataContractSurrogate(adapter); }
public SurrogatesExtension(ISerializationSurrogateProvider provider) => _provider = provider;
public static IConfigurationContainer Register(this IConfigurationContainer @this, ISerializationSurrogateProvider provider) => @this.Extend(new SurrogatesExtension(provider));
public static void SetSerializationSurrogateProvider(this DataContractSerializer serializer, ISerializationSurrogateProvider provider) { serializer.SerializationSurrogateProvider = provider; }
public SurrogateProviderAdapter(ISerializationSurrogateProvider provider) { _provider = provider; }