12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #if FEAT_SERVICEMODEL && PLAT_XMLSERIALIZER
- using System;
- using System.Collections.Generic;
- using System.Runtime.Serialization;
- using System.ServiceModel.Description;
- using System.Xml;
- using ProtoBuf.Meta;
- namespace ProtoBuf.ServiceModel
- {
-
-
-
- public sealed class ProtoOperationBehavior : DataContractSerializerOperationBehavior
- {
- private TypeModel model;
-
-
-
- public ProtoOperationBehavior(OperationDescription operation) : base(operation)
- {
- #if !NO_RUNTIME
- model = RuntimeTypeModel.Default;
- #endif
- }
-
-
-
- public TypeModel Model
- {
- get { return model; }
- set
- {
- model = value ?? throw new ArgumentNullException(nameof(value));
- }
- }
-
-
-
-
- public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes)
- {
- if (model == null) throw new InvalidOperationException("No Model instance has been assigned to the ProtoOperationBehavior");
- return XmlProtoSerializer.TryCreate(model, type) ?? base.CreateSerializer(type, name, ns, knownTypes);
- }
- }
- }
- #endif
|