internal XmlObjectSerializerReadContextComplex(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver)
     : base(serializer, rootTypeDataContract, dataContractResolver)
 {
     _mode = SerializationMode.SharedContract;
     _preserveObjectReferences = serializer.PreserveObjectReferences;
     _serializationSurrogateProvider = serializer.SerializationSurrogateProvider;
 }
예제 #2
0
 internal XmlObjectSerializerWriteContextComplex(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver)
     : base(serializer, rootTypeDataContract, dataContractResolver)
 {
     _mode = SerializationMode.SharedContract;
     this.preserveObjectReferences   = serializer.PreserveObjectReferences;
     _serializationSurrogateProvider = serializer.SerializationSurrogateProvider;
 }
예제 #3
0
 internal static Type GetDataContractType(ISerializationSurrogateProvider surrogateProvider, Type type)
 {
     if (DataContract.GetBuiltInDataContract(type) != null)
     {
         return(type);
     }
     return(surrogateProvider.GetSurrogateType(type) ?? type);
 }
예제 #4
0
 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);
 }
예제 #5
0
        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);
        }
예제 #7
0
 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));
 }
예제 #8
0
        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);
            }
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
 public SurrogateProviderAdapter(ISerializationSurrogateProvider provider)
 {
     _provider = provider;
 }
예제 #11
0
        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);
        }
예제 #12
0
 internal static Type GetDataContractType(ISerializationSurrogateProvider surrogateProvider, Type type)
 {
     if (DataContract.GetBuiltInDataContract(type) != null)
         return type;
     return surrogateProvider.GetSurrogateType(type) ?? type;
 }
예제 #13
0
 public static void SetSerializationSurrogateProvider(this DataContractSerializer serializer, ISerializationSurrogateProvider provider)
 {
     serializer.SerializationSurrogateProvider = provider;
 }
예제 #14
0
 internal static Type GetSurrogatedType(ISerializationSurrogateProvider serializationSurrogateProvider, Type type)
 {
     return DataContractSurrogateCaller.GetDataContractType(serializationSurrogateProvider, DataContract.UnwrapNullableType(type));
 }
예제 #15
0
 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;
 }
예제 #16
0
 internal static Type GetSurrogatedType(ISerializationSurrogateProvider serializationSurrogateProvider, Type type)
 {
     return(DataContractSurrogateCaller.GetDataContractType(serializationSurrogateProvider, DataContract.UnwrapNullableType(type)));
 }
예제 #17
0
        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);
        }
예제 #18
0
 public SurrogatesExtension(ISerializationSurrogateProvider provider) => _provider = provider;
예제 #19
0
 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;
 }