Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
1851676b
Commit
1851676b
authored
Aug 12, 2011
by
csharptest
Committed by
rogerk
Aug 12, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow field names that begin with underscore and number '_0'
parent
50a89c1c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
2 deletions
+29
-2
unittest_issues.proto
protos/extest/unittest_issues.proto
+6
-0
ExtensionGenerator.cs
src/ProtoGen/ExtensionGenerator.cs
+3
-0
MessageGenerator.cs
src/ProtoGen/MessageGenerator.cs
+3
-0
UnitTestExtrasIssuesProtoFile.cs
...lBuffers.Test/TestProtos/UnitTestExtrasIssuesProtoFile.cs
+0
-0
FieldDescriptor.cs
src/ProtocolBuffers/Descriptors/FieldDescriptor.cs
+6
-1
NameHelpers.cs
src/ProtocolBuffers/NameHelpers.cs
+11
-1
No files found.
protos/extest/unittest_issues.proto
View file @
1851676b
...
...
@@ -80,3 +80,9 @@ message B {
message
AB
{
optional
int32
a_b
=
1
;
}
// Similar issue with numberic names
message
NumberField
{
optional
int32
_01
=
1
;
}
src/ProtoGen/ExtensionGenerator.cs
View file @
1851676b
...
...
@@ -75,6 +75,9 @@ namespace Google.ProtocolBuffers.ProtoGen
public
void
Generate
(
TextGenerator
writer
)
{
if
(
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
&&
GetFieldConstantName
(
Descriptor
).
StartsWith
(
"_"
))
writer
.
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
writer
.
WriteLine
(
"public const int {0} = {1};"
,
GetFieldConstantName
(
Descriptor
),
Descriptor
.
FieldNumber
);
if
(
UseLiteRuntime
)
...
...
src/ProtoGen/MessageGenerator.cs
View file @
1851676b
...
...
@@ -246,6 +246,9 @@ namespace Google.ProtocolBuffers.ProtoGen
foreach
(
FieldDescriptor
fieldDescriptor
in
Descriptor
.
Fields
)
{
if
(
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
&&
GetFieldConstantName
(
fieldDescriptor
).
StartsWith
(
"_"
))
writer
.
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
// Rats: we lose the debug comment here :(
writer
.
WriteLine
(
"public const int {0} = {1};"
,
GetFieldConstantName
(
fieldDescriptor
),
fieldDescriptor
.
FieldNumber
);
...
...
src/ProtocolBuffers.Test/TestProtos/UnitTestExtrasIssuesProtoFile.cs
View file @
1851676b
This diff is collapsed.
Click to expand it.
src/ProtocolBuffers/Descriptors/FieldDescriptor.cs
View file @
1851676b
...
...
@@ -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
...
...
src/ProtocolBuffers/NameHelpers.cs
View file @
1851676b
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment