| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Runtime.Serialization; |
| | | 7 | | using System.Runtime.Serialization.Json; |
| | | 8 | | using System.Xml; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.Description |
| | | 11 | | { |
| | | 12 | | internal class DataContractJsonSerializerOperationBehavior : DataContractSerializerOperationBehavior |
| | | 13 | | { |
| | | 14 | | private readonly bool _alwaysEmitTypeInformation; |
| | | 15 | | |
| | | 16 | | public DataContractJsonSerializerOperationBehavior(OperationDescription description, int maxItemsInObjectGraph, |
| | 0 | 17 | | : base(description) |
| | | 18 | | { |
| | 0 | 19 | | MaxItemsInObjectGraph = maxItemsInObjectGraph; |
| | 0 | 20 | | IgnoreExtensionDataObject = ignoreExtensionDataObject; |
| | 0 | 21 | | _alwaysEmitTypeInformation = alwaysEmitTypeInformation; |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | public override XmlObjectSerializer CreateSerializer(Type type, string name, string ns, IList<Type> knownTypes) |
| | | 25 | | { |
| | 0 | 26 | | return new DataContractJsonSerializer(type, new DataContractJsonSerializerSettings |
| | 0 | 27 | | { |
| | 0 | 28 | | RootName = name, |
| | 0 | 29 | | KnownTypes = knownTypes, |
| | 0 | 30 | | MaxItemsInObjectGraph = MaxItemsInObjectGraph, |
| | 0 | 31 | | IgnoreExtensionDataObject = IgnoreExtensionDataObject, |
| | 0 | 32 | | EmitTypeInformation = _alwaysEmitTypeInformation ? EmitTypeInformation.Always : EmitTypeInformation.AsNe |
| | 0 | 33 | | }); |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns |
| | | 37 | | { |
| | 0 | 38 | | return new DataContractJsonSerializer(type, new DataContractJsonSerializerSettings |
| | 0 | 39 | | { |
| | 0 | 40 | | RootName = name.Value, |
| | 0 | 41 | | KnownTypes = knownTypes, |
| | 0 | 42 | | MaxItemsInObjectGraph = MaxItemsInObjectGraph, |
| | 0 | 43 | | IgnoreExtensionDataObject = IgnoreExtensionDataObject, |
| | 0 | 44 | | EmitTypeInformation = _alwaysEmitTypeInformation ? EmitTypeInformation.Always : EmitTypeInformation.AsNe |
| | 0 | 45 | | }); |
| | | 46 | | } |
| | | 47 | | } |
| | | 48 | | } |