2
votes

Have funny error in protobuf-net generated code. .proto definition file contains field named "value" for an object. What protogen.exe generated for that value with -p:detectMissing option:

    private int? _value;
    [global::ProtoBuf.ProtoMember(50, IsRequired = false, Name=@"value", DataFormat = global::ProtoBuf.DataFormat.TwosComplement)]
    [global::System.Xml.Serialization.XmlElement(@"value", Order = 50)]

    public int value
    {
        get { return _value ?? default(int); }
        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 : (int?)null; }
    }
    private bool ShouldSerializevalue() { return valueSpecified; }
    private void Resetvalue() { valueSpecified = false; }

Compiler produces an error thinking that value is a keyword but not class property:

Type of conditional expression cannot be determined because there is no implicit conversion between 'bool' and 'int?'

Made workaround manually altering generated code:

public int valueWorkaround
{
    get { return _value ?? default(int); }
}

public bool valueSpecified
{
  get { return _value != null; }
    set { if (value == (_value == null)) _value = value ? valueWorkaround : (int?)null; }
}

However probably it makes sense to fix code generation also?

1
Hmmm... there is keyword-checking code in there (for adding @ etc) - guess I missed one. I'll take a look. - Marc Gravell
@marc I'm facing the same issue on two different computers (with same version of VS and ProtoBufGenerator) ... On one computer the this is added correctly while on other computer it is not ... extremely strange ... Can't really tell for ProtoBufGenerator version as dll indicate 1.0.0.0 (Installer we used for both computers was protobuf-net-VS10.msi). - CitizenInsane
@CitizenInsane in the install folder you should be able to compare the files directly; for codegen, the most important things are the xslt, however: the version from protobuf-net.dll will help understand exactly what point in time (svn commit) they were built from - Marc Gravell
@marc Thank you Marc, indeed if starting from same installer, someone manually edited the csharp.xslt file and prefixed XXX with this.XXX when generating code for public bool XXXSpecified to workaround fields called value ... he just forgot to warn everyone in the team for this modification. - CitizenInsane
@marc @aleksey For information, I have placed modified csharp.xslt here: gist.github.com/3748744 ... Only few lines have been modified compared to the one installed with protobuf-net-VS10.msi and intend only to workaround fields named value - CitizenInsane

1 Answers

0
votes

Yes, it makes sense to fix the code generation. I guess, you should report it to the project contributors.