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
8fcde2ca
Commit
8fcde2ca
authored
Jun 12, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix oneof behaviour in the face of default values.
parent
ca2adbd5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
9 deletions
+4
-9
csharp_primitive_field.cc
...google/protobuf/compiler/csharp/csharp_primitive_field.cc
+4
-9
No files found.
src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
View file @
8fcde2ca
...
...
@@ -137,8 +137,6 @@ PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {
}
void
PrimitiveOneofFieldGenerator
::
GenerateMembers
(
io
::
Printer
*
printer
)
{
// TODO(jonskeet): What should foo.OneofIntField = 0; do? Clear the oneof?
// Currently foo.OneOfStringField = null will clear the oneof, but foo.OneOfStringField = "" won't. Ick.
AddDeprecatedFlag
(
printer
);
printer
->
Print
(
variables_
,
...
...
@@ -148,15 +146,14 @@ void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
if
(
is_value_type
)
{
printer
->
Print
(
variables_
,
" $oneof_name$_ = value;
\n
"
" $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;
\n
"
);
" $oneof_name$_ = value;
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
" $oneof_name$_ = value ?? $default_value$;
\n
"
" $oneof_name$Case_ = value == null ? $oneof_property_name$OneofCase.None : $oneof_property_name$OneofCase.$property_name$;
\n
"
);
" $oneof_name$_ = value ?? $default_value$;
\n
"
);
}
printer
->
Print
(
" $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;
\n
"
" }
\n
"
"}
\n
"
);
}
...
...
@@ -167,11 +164,9 @@ void PrimitiveOneofFieldGenerator::WriteToString(io::Printer* printer) {
}
void
PrimitiveOneofFieldGenerator
::
GenerateParsingCode
(
io
::
Printer
*
printer
)
{
// TODO(jonskeet): What if the value we read is the default value for the type?
printer
->
Print
(
variables_
,
"$oneof_name$_ = input.Read$capitalized_type_name$()
\n
;"
"$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;
\n
"
);
"$property_name$ = input.Read$capitalized_type_name$()
\n
;"
);
}
}
// namespace csharp
...
...
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