diff options
Diffstat (limited to 'src/ProtocolBuffers')
-rw-r--r-- | src/ProtocolBuffers/Descriptors/FieldDescriptor.cs | 7 | ||||
-rw-r--r-- | src/ProtocolBuffers/NameHelpers.cs | 12 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs b/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs index 8653a078..6d9de74f 100644 --- a/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs +++ b/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs @@ -352,7 +352,12 @@ namespace Google.ProtocolBuffers.Descriptors public bool IsCLSCompliant
{
- get { return mappedType != MappedType.UInt32 && mappedType != MappedType.UInt64; }
+ get
+ {
+ return mappedType != MappedType.UInt32 &&
+ mappedType != MappedType.UInt64 &&
+ !NameHelpers.UnderscoresToPascalCase(Name).StartsWith("_");
+ }
}
public int FieldNumber
diff --git a/src/ProtocolBuffers/NameHelpers.cs b/src/ProtocolBuffers/NameHelpers.cs index bd93d30b..3d2be22d 100644 --- a/src/ProtocolBuffers/NameHelpers.cs +++ b/src/ProtocolBuffers/NameHelpers.cs @@ -67,12 +67,22 @@ namespace Google.ProtocolBuffers private static string UnderscoresToPascalOrCamelCase(string input, bool pascal)
{
string name = Transform(input, pascal ? UnderlineToPascal : UnderlineToCamel, x => x.Value.TrimStart('_').ToUpper());
- if (!pascal && name.Length > 0 && Char.IsUpper(name[0]))
+
+ if (name.Length == 0)
+ throw new ArgumentException(String.Format("The field name '{0}' is invalid.", input));
+
+ // Pascal case always begins with lower-case letter
+ if (!pascal && Char.IsUpper(name[0]))
{
char[] chars = name.ToCharArray();
chars[0] = char.ToLower(chars[0]);
return new string(chars);
}
+
+ // Fields can not start with a number
+ if (Char.IsNumber(name[0]))
+ name = '_' + name;
+
return name;
}
|