public void IDataContractSurrogate()
        {
            var orders = dbContext.Orders.ToArray();
            var knownTypes = new List<Type>
            {
                typeof (Order)
            };

            IDataContractSurrogate surrogate = new OrderSurrogate();
            var tester = new XmlDataContractSerializerTester<IEnumerable<Order>>(
                new DataContractSerializer(typeof(IEnumerable<Order>), knownTypes, Int32.MaxValue, false, true,
                    surrogate),
                true);

            tester.SerializeAndDeserialize(orders);
        }
Exemplo n.º 2
0
        public object GetObjectToSerialize(object obj, Type targetType)
        {
            Console.WriteLine("OrderDataContractSurrogate.GetObjectToSerialize() invoked.");

            if (obj is Order order)
            {
                var serializer     = new XmlSerializer(typeof(Order));
                var writer         = new StringWriter();
                var orderSurrogate = new OrderSurrogate();

                serializer.Serialize(writer, order);
                orderSurrogate.XmlData = writer.ToString();

                return(orderSurrogate);
            }

            return(obj);
        }