Serialization 告诉protobuf net在使用反射构建模型时使用DataFormat.WellKnown

Serialization 告诉protobuf net在使用反射构建模型时使用DataFormat.WellKnown,serialization,protocol-buffers,protobuf-net,Serialization,Protocol Buffers,Protobuf Net,我不知道如何告诉protobuf net在使用反射构建模型时如何使用Google时间戳类型而不是protobuf net类型,在这种情况下,我无法对应该序列化的类进行注释 我添加如下属性: ProtoBuf.Meta.RuntimeTypeModel.Default[propertyInfo.DeclaringType].Add(tag, propertyInfo.Name); [ProtoContract] public class TestClass { [ProtoMember

我不知道如何告诉protobuf net在使用反射构建模型时如何使用Google时间戳类型而不是protobuf net类型,在这种情况下,我无法对应该序列化的类进行注释

我添加如下属性:

ProtoBuf.Meta.RuntimeTypeModel.Default[propertyInfo.DeclaringType].Add(tag, propertyInfo.Name); 
[ProtoContract]
public class TestClass
{
    [ProtoMember(1, DataFormat = DataFormat.WellKnown) ]
    public DateTime StartTime { get; set; }
}
但如果我对该属性进行注释,它将如下所示:

ProtoBuf.Meta.RuntimeTypeModel.Default[propertyInfo.DeclaringType].Add(tag, propertyInfo.Name); 
[ProtoContract]
public class TestClass
{
    [ProtoMember(1, DataFormat = DataFormat.WellKnown) ]
    public DateTime StartTime { get; set; }
}

因此,基本上我需要告诉运行时类型模型使用数据格式。这将返回该字段的
ValueMember
,其中包括
.DataFormat
属性。

使用
AddField
而不是
Add
(这是一个流畅的API)。这将返回字段的
ValueMember
,其中包括
.DataFormat
属性