Files
2026-08-27 10:56:38 -06:00

41 lines
1.0 KiB
C#

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 TypeModel Model
{
get
{
return model;
}
set
{
model = value ?? throw new ArgumentNullException("value");
}
}
public ProtoOperationBehavior(OperationDescription operation)
: base(operation)
{
model = RuntimeTypeModel.Default;
}
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 (XmlObjectSerializer)(((object)XmlProtoSerializer.TryCreate(model, type)) ?? ((object)((DataContractSerializerOperationBehavior)this).CreateSerializer(type, name, ns, knownTypes)));
}
}