我正在尝试从 .proto 文件生成协议缓冲区 C# 代码,不幸的是,protobuf-net 正在生成无法编译的代码。
我的 .proto 中导致问题的具体部分是:
// Counter value response
message RpbCounterGetResp {
optional sint64 value = 1;
}
当 protobuf-net 使用命令行工具自动生成时'C:\Program Files (x86)\protobuf-net\protobuf-net-VS9\protogen.exe' -p:detectMissing -ns:CorrugatedIron.Messages -i:riak_kv.proto -o:riak_kv.cs
我得到以下块 o' 不可编译的代码:
[global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"RpbCounterUpdateResp")]
public partial class RpbCounterUpdateResp : global::ProtoBuf.IExtensible, global::System.ComponentModel.INotifyPropertyChanging
{
public RpbCounterUpdateResp() {}
private long? _value;
[global::ProtoBuf.ProtoMember(1, IsRequired = false, Name=@"value", DataFormat = global::ProtoBuf.DataFormat.ZigZag)]
public long value
{
get { return _value?? default(long); }
set { OnPropertyChanging(@"value"); _value = value; }
}
[global::System.Xml.Serialization.XmlIgnore]
[global::System.ComponentModel.Browsable(false)]
public bool valueSpecified
{
get { return _value != null; }
/* this is the big that won't compile as there's no conversion
between bool and System.Nullable<long>
*/
set { if (value == (_value== null)) _value = value ? value : (long?)null; }
}
private bool ShouldSerializevalue() { return valueSpecified; }
private void Resetvalue() { valueSpecified = false; }
public event global::System.ComponentModel.PropertyChangingEventHandler PropertyChanging;
protected virtual void OnPropertyChanging(string propertyName)
{ if(PropertyChanging != null) PropertyChanging(this, new global::System.ComponentModel.PropertyChangingEventArgs(propertyName)); }
private global::ProtoBuf.IExtension extensionObject;
global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
{ return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); }
}
是否可以提供额外的 protogen 选项来纠正此问题?