Closed GoogleCodeExporter closed 8 years ago
If you are generating from a .proto schema with protogen, by *default*
protobuf-net just gives the raw values; however, you can use the
`detectMissing` switch , which will cause the code-gen to add `*Specified`
properties and `ShouldSerialize*` methods (these are standard .NET naming
conventions used by and recognised by several framework classes). The
`*Specified` operates like `has_*`. IIRC, `/p:detectMissing` at the
command-line should enable that.
Original comment by marc.gravell
on 19 Sep 2013 at 8:56
Hi,
ok, i added the detectMissing switch to the command and now it indeed generates
the *Specified functions. Still, compilation does not work and it is for a very
"funny" reason. One of our fields is named "value", and, the generator does not
complain on this, but, the compiler does because in the set{} and get{}
functions that it generates, value is C# keyword. For boolean proprties it does
not even complain, but then value is not necesarilly connect. For int and other
properties, it complains about type mismatches, because it mistakes the keyword
"value" with the field named "value" (luckily we detected it that way, because
with booleans only we would not have found out)
In C++ this of course does not give any issues since value is not a keyword,
and value is also not a predefined keyword in the protocol buffer definition if
I'm not mistaken. Of course, "simple" solution would be to rename the field,
or, do you think that everything that is possible in protocol buffers should be
possible in protobuf-net, and thus in this case, a fix has to be made to
protobuf-net to enable this?
Kind regards, and thx already for the extremely fast response !!
Wim
private byte[] _value;
[global::ProtoBuf.ProtoMember(2, IsRequired = false, Name=@"value", DataFormat = global::ProtoBuf.DataFormat.Default)]
public byte[] value
{
get { return _value?? null; }
set { _value = value; }
}
[global::System.Xml.Serialization.XmlIgnore]
[global::System.ComponentModel.Browsable(false)]
public bool valueSpecified
{
get { return _value != null; }
set { if (value == (_value== null)) _value = value ? value : (byte[])null; } //--> Compiler fails here, value is keyword, but also byte[] field from the message
}
private bool ShouldSerializevalue() { return valueSpecified; }
private void Resetvalue() { valueSpecified = false; }
Original comment by WVHInfor...@gmail.com
on 19 Sep 2013 at 9:40
Yes, that is a bug; fixed in r667 - you can just take the csharp.xslt from here
(https://protobuf-net.googlecode.com/svn/trunk/ProtoGen/csharp.xslt) and copy
it over the one in your protogen.exe folder - it will pick it up from there
Original comment by marc.gravell
on 19 Sep 2013 at 10:08
Ok, thx again for the swift response and solution.
Original comment by WVHInfor...@gmail.com
on 19 Sep 2013 at 10:58
Original issue reported on code.google.com by
WVHInfor...@gmail.com
on 19 Sep 2013 at 7:45