Serialization Protobuf net跳过特定字段的反序列化

Serialization Protobuf net跳过特定字段的反序列化,serialization,protobuf-net,Serialization,Protobuf Net,我已序列化此类: [ProtoContract] public class TestClass { [ProtoMember(1)] public int[] hugeArray; [ProtoMember(2)] public int x; [ProtoMember(3)] public int y; //lot more fields and properties to serialize here... } 如何在反序列化过程中跳过[ProtoMembe

我已序列化此类:

[ProtoContract]
public class TestClass
{
    [ProtoMember(1)] public int[] hugeArray;
    [ProtoMember(2)] public int x;
    [ProtoMember(3)] public int y;
    //lot more fields and properties to serialize here...

}
如何在反序列化过程中跳过[ProtoMember(1)]hugarray,以便只反序列化x、y和其他字段

我的问题是,有时我只需要快速获取“元数据”,这是其他字段和属性所描述的,但有时我需要整个对象。

两个选项:

  • 两个
    RuntimeTypeModel
    实例(一个手动构建,仅指定所需字段)
  • 两种类型;i、 e.创建一个更简单的
    TestClass
    ,它只是省略了大字段,即
    TestClassMetadata
    ,并反序列化到该字段中;protobuf网络不会介意的

我的类有30个字段,我试图避免在反序列化过程中为了跳过1个字段而重复代码。我想要(伪代码):RuntimeTypeModel.BuildModelFor(typeof(TestClass)).RemoveMember(1),但我不认为protobuf net提供了类似的东西。@Michal确实-没有Remove;需要TypeModel.Create(),添加(type,false),然后添加所需的成员