aboutsummaryrefslogtreecommitdiff
path: root/src/ProtoGen/FieldGeneratorBase.cs
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2010-11-09 20:49:12 -0600
committercsharptest <roger@csharptest.net>2010-11-09 20:49:12 -0600
commit272cb8aee775de65e08b4ab17c485cd678d08266 (patch)
tree3489244ff5bd901592b535ea5ad9352096d1521f /src/ProtoGen/FieldGeneratorBase.cs
parente49547735834485dd22842e1a82bc5ae4139b8a8 (diff)
downloadprotobuf-272cb8aee775de65e08b4ab17c485cd678d08266.tar.gz
protobuf-272cb8aee775de65e08b4ab17c485cd678d08266.tar.bz2
protobuf-272cb8aee775de65e08b4ab17c485cd678d08266.zip
Lite feature complete.
Diffstat (limited to 'src/ProtoGen/FieldGeneratorBase.cs')
-rw-r--r--src/ProtoGen/FieldGeneratorBase.cs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ProtoGen/FieldGeneratorBase.cs b/src/ProtoGen/FieldGeneratorBase.cs
index 3520dc9e..45a096a0 100644
--- a/src/ProtoGen/FieldGeneratorBase.cs
+++ b/src/ProtoGen/FieldGeneratorBase.cs
@@ -42,6 +42,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
: base(descriptor) {
}
+ public abstract void WriteHash(TextGenerator writer);
+ public abstract void WriteEquals(TextGenerator writer);
+ public abstract void WriteToString(TextGenerator writer);
+
private static bool AllPrintableAscii(string text) {
foreach (char c in text) {
if (c < 0x20 || c > 0x7e) {
@@ -73,11 +77,30 @@ namespace Google.ProtocolBuffers.ProtoGen {
case FieldType.UInt32:
case FieldType.UInt64:
case FieldType.Fixed32:
- case FieldType.Fixed64:
+ case FieldType.Fixed64:
+ {
// The simple Object.ToString converts using the current culture.
// We want to always use the invariant culture so it's predictable.
IConvertible value = (IConvertible) Descriptor.DefaultValue;
+ //a few things that must be handled explicitly
+ if (Descriptor.FieldType == FieldType.Double && value is double) {
+ if (double.IsNaN((double) value))
+ return "double.NaN";
+ if (double.IsPositiveInfinity((double) value))
+ return "double.PositiveInfinity";
+ if (double.IsNegativeInfinity((double) value))
+ return "double.NegativeInfinity";
+ }
+ else if (Descriptor.FieldType == FieldType.Float && value is float) {
+ if (float.IsNaN((float)value))
+ return "float.NaN";
+ if (float.IsPositiveInfinity((float)value))
+ return "float.PositiveInfinity";
+ if (float.IsNegativeInfinity((float)value))
+ return "float.NegativeInfinity";
+ }
return value.ToString(CultureInfo.InvariantCulture) + suffix;
+ }
case FieldType.Bool:
return (bool) Descriptor.DefaultValue ? "true" : "false";