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
2b0a18b2
Commit
2b0a18b2
authored
Oct 05, 2018
by
Sydney Acksman
Committed by
Jie Luo
Oct 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add C# compiler option to add System.SerializableAttribute to generated message classes (#5208)
parent
f50a1f84
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
1 deletion
+16
-1
csharp_generator.cc
src/google/protobuf/compiler/csharp/csharp_generator.cc
+2
-0
csharp_message.cc
src/google/protobuf/compiler/csharp/csharp_message.cc
+8
-0
csharp_message.h
src/google/protobuf/compiler/csharp/csharp_message.h
+1
-0
csharp_options.h
src/google/protobuf/compiler/csharp/csharp_options.h
+5
-1
No files found.
src/google/protobuf/compiler/csharp/csharp_generator.cc
View file @
2b0a18b2
...
...
@@ -81,6 +81,8 @@ bool Generator::Generate(
cli_options
.
base_namespace_specified
=
true
;
}
else
if
(
options
[
i
].
first
==
"internal_access"
)
{
cli_options
.
internal_access
=
true
;
}
else
if
(
options
[
i
].
first
==
"serializable"
)
{
cli_options
.
serializable
=
true
;
}
else
{
*
error
=
"Unknown generator option: "
+
options
[
i
].
first
;
return
false
;
...
...
src/google/protobuf/compiler/csharp/csharp_message.cc
View file @
2b0a18b2
...
...
@@ -42,6 +42,7 @@
#include <google/protobuf/wire_format.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/compiler/csharp/csharp_options.h>
#include <google/protobuf/compiler/csharp/csharp_doc_comment.h>
#include <google/protobuf/compiler/csharp/csharp_enum.h>
#include <google/protobuf/compiler/csharp/csharp_field_base.h>
...
...
@@ -105,6 +106,12 @@ void MessageGenerator::AddDeprecatedFlag(io::Printer* printer) {
}
}
void
MessageGenerator
::
AddSerializableAttribute
(
io
::
Printer
*
printer
)
{
if
(
this
->
options
()
->
serializable
)
{
printer
->
Print
(
"[global::System.SerializableAttribute]
\n
"
);
}
}
void
MessageGenerator
::
Generate
(
io
::
Printer
*
printer
)
{
std
::
map
<
string
,
string
>
vars
;
vars
[
"class_name"
]
=
class_name
();
...
...
@@ -112,6 +119,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
WriteMessageDocComment
(
printer
,
descriptor_
);
AddDeprecatedFlag
(
printer
);
AddSerializableAttribute
(
printer
);
printer
->
Print
(
vars
,
...
...
src/google/protobuf/compiler/csharp/csharp_message.h
View file @
2b0a18b2
...
...
@@ -70,6 +70,7 @@ class MessageGenerator : public SourceGeneratorBase {
bool
HasNestedGeneratedTypes
();
void
AddDeprecatedFlag
(
io
::
Printer
*
printer
);
void
AddSerializableAttribute
(
io
::
Printer
*
printer
);
std
::
string
class_name
();
std
::
string
full_class_name
();
...
...
src/google/protobuf/compiler/csharp/csharp_options.h
View file @
2b0a18b2
...
...
@@ -45,7 +45,8 @@ struct Options {
file_extension
(
".cs"
),
base_namespace
(
""
),
base_namespace_specified
(
false
),
internal_access
(
false
)
{
internal_access
(
false
),
serializable
(
false
)
{
}
// Extension of the generated file. Defaults to ".cs"
string
file_extension
;
...
...
@@ -68,6 +69,9 @@ struct Options {
// Whether the generated classes should have accessibility level of "internal".
// Defaults to false that generates "public" classes.
bool
internal_access
;
// Whether the generated classes should have a global::System.Serializable attribute added
// Defaults to false
bool
serializable
;
};
}
// 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