C# Protobuf net生成SomeType[]而不是列表<;SomeType>;
在我的.proto文件中C# Protobuf net生成SomeType[]而不是列表<;SomeType>;,c#,protocol-buffers,protobuf-net,C#,Protocol Buffers,Protobuf Net,在我的.proto文件中 message OrderInputData { /// collection of Products repeated double productColl = 1; /// collection of Item repeated string itemsColl = 2 ; /// collection of quantity repeated int32 quantityColl
message OrderInputData
{
/// collection of Products
repeated double productColl = 1;
/// collection of Item
repeated string itemsColl = 2 ;
/// collection of quantity
repeated int32 quantityColl = 3 ;
/// collection of ids. if left empty, all products are going to be considered
repeated int32 idColl = 4;
}
创建C#的命令是:
它创造
public partial class OrderInputData : global::ProtoBuf.IExtensible
{
private global::ProtoBuf.IExtension __pbn__extensionData;
global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
=> global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
[global::ProtoBuf.ProtoMember(1)]
public double[] productColl { get; set; }
[global::ProtoBuf.ProtoMember(2)]
public global::System.Collections.Generic.List<string> itemsColl { get; } = new global::System.Collections.Generic.List<string>();
[global::ProtoBuf.ProtoMember(3)]
public int[] quantityColl { get; set; }
[global::ProtoBuf.ProtoMember(4)]
public int[] idColl { get; set; }
}
公共分部类OrderInputData:global::ProtoBuf.IEExtensible
{
私有全局::ProtoBuf.IExtension _pbn__extensionData;
全局::ProtoBuf.IExtension全局::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
=>global::ProtoBuf.Extensible.GetExtensionObject(ref\uu pbn\uu extensionData,createIfMissing);
[全球::原成员(1)]
public double[]productColl{get;set;}
[全球::原成员(2)]
public global::System.Collections.Generic.List itemsColl{get;}=new global::System.Collections.Generic.List();
[全球::原成员(3)]
public int[]quantityColl{get;set;}
[全球::原成员(4)]
公共int[]idColl{get;set;}
}
但我期待的是
public partial class OrderInputData : global::ProtoBuf.IExtensible
{
private global::ProtoBuf.IExtension __pbn__extensionData;
global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
=> global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
[global::ProtoBuf.ProtoMember(1)]
public global::System.Collections.Generic.List<double> productColl { get; } = new global::System.Collections.Generic.List<double>();
[global::ProtoBuf.ProtoMember(2)]
public global::System.Collections.Generic.List<string> itemsColl { get; } = new global::System.Collections.Generic.List<string>();
[global::ProtoBuf.ProtoMember(3)]
public global::System.Collections.Generic.List<int> quantityColl { get; } = new global::System.Collections.Generic.List<int>();
[global::ProtoBuf.ProtoMember(4)]
public global::System.Collections.Generic.List<int> idColl { get; } = new global::System.Collections.Generic.List<int>();
}
公共分部类OrderInputData:global::ProtoBuf.IEExtensible
{
私有全局::ProtoBuf.IExtension _pbn__extensionData;
全局::ProtoBuf.IExtension全局::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
=>global::ProtoBuf.Extensible.GetExtensionObject(ref\uu pbn\uu extensionData,createIfMissing);
[全球::原成员(1)]
public global::System.Collections.Generic.List productColl{get;}=new global::System.Collections.Generic.List();
[全球::原成员(2)]
public global::System.Collections.Generic.List itemsColl{get;}=new global::System.Collections.Generic.List();
[全球::原成员(3)]
public global::System.Collections.Generic.List quantityColl{get;}=new global::System.Collections.Generic.List();
[全球::原成员(4)]
public global::System.Collections.Generic.List idColl{get;}=new global::System.Collections.Generic.List();
}
我是否在创建cs的命令中遗漏了任何内容?当我用旧版本的Protogen创建时,它是预期的代码,但不是现在最新版本的Protogen,
protobuf net.Reflection对大多数内置原语使用数组,对其他类型(消息等)使用列表:
受保护的虚拟布尔UseArray(FieldDescriptorProto字段)
{
开关(字段类型)
{
案例字段描述符proto.Type.TypeBool:
案例字段描述符Proto.Type.TypeDouble:
案例字段描述符proto.Type.TypeFixed32:
案例字段描述符proto.Type.TypeFixed64:
案例字段描述符proto.Type.TypeFloat:
案例字段描述符proto.Type.TypeInt32:
案例字段描述符proto.Type.TypeInt64:
案例字段描述符Proto.Type.TypeSfixed32:
案例字段描述符Proto.Type.TypeSfixed64:
案例字段描述符Proto.Type.TypeSint32:
案例字段描述符proto.Type.TypeSint64:
案例字段描述符proto.Type.TypeUint32:
案例字段描述符Proto.Type.TypeUint64:
返回true;
违约:
返回false;
}
}
我很乐意考虑转换这个行为——这将是非常微不足道的——但是:它现在不存在。2018年有一个问题:旁注:现在使用.proto-to-C代码gen的
protobuf-net.BuildTools
要容易得多:-同样值得注意的是,您可以先使用代码,然后就完全失去了.proto。谢谢,我修改了我的代码,一切都很好now@melom仅供参考,因为它已经出现过多次,如果我有时间的话,我今天打算为这个添加一个设置
public partial class OrderInputData : global::ProtoBuf.IExtensible
{
private global::ProtoBuf.IExtension __pbn__extensionData;
global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
=> global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
[global::ProtoBuf.ProtoMember(1)]
public global::System.Collections.Generic.List<double> productColl { get; } = new global::System.Collections.Generic.List<double>();
[global::ProtoBuf.ProtoMember(2)]
public global::System.Collections.Generic.List<string> itemsColl { get; } = new global::System.Collections.Generic.List<string>();
[global::ProtoBuf.ProtoMember(3)]
public global::System.Collections.Generic.List<int> quantityColl { get; } = new global::System.Collections.Generic.List<int>();
[global::ProtoBuf.ProtoMember(4)]
public global::System.Collections.Generic.List<int> idColl { get; } = new global::System.Collections.Generic.List<int>();
}