DerrickBrayanClayton / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

GetProto wrong writes string types in default property #24

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

What steps will reproduce the problem?
1.
declare contract
    [ProtoContract]
    class MyClass
    {
        [ProtoMember(1), DefaultValue("Test Test TEst")]
        public string TestString;
    }
2.
get proto desription
string proto = Serializer.GetProto<MyClass>();

What is the expected output? What do you see instead?
expected:
variable proto contains
message MyClass {
   optional string TestString = 1 [default = "Test Test TEst"];
}
see instead:
message MyClass {
   optional string TestString = 1 [default = Test Test TEst];
}

Please provide any additional information below.
I correct this issue with next code:

object def = prop.DefaultValue;
if (def != null)
{
    if (prop.DefinedType == "string")
    {
        def = "\"" + def.ToString() + "\"";
    }
    string defText = Convert.ToString(def, 
CultureInfo.InvariantCulture);
    sb.Append(" [default = ").Append(defText).Append("]");
}

Original issue reported on code.google.com by fghfdjwr...@gmail.com on 7 Oct 2008 at 11:35

GoogleCodeExporter commented 8 years ago
Thankyou for the very clear bug report; I've patched this in r174 - note that 
the 
language spec doesn't make the escaping rules clear, so this may change again 
once 
these have clarified. Test added (now passes) as per above.

Original comment by marc.gravell on 7 Oct 2008 at 12:13

GoogleCodeExporter commented 8 years ago

Original comment by marc.gravell on 8 Nov 2008 at 9:27