[英]protobuf-net and optional values
我正在嘗試從.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
我得到以下大塊的不可編譯代碼:
[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); }
}
是否可以提供其他原體選項來解決此問題?
事實證明,這是由名為value
的.proto屬性之間的C#保留關鍵字沖突引起的,該屬性產生了無法編譯的代碼。 將自動生成的屬性的名稱更改為returnValue
解決問題……直到下一次代碼自動生成為止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.