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
61d75cb8
Unverified
Commit
61d75cb8
authored
Nov 04, 2019
by
Jan Tattermusch
Committed by
GitHub
Nov 04, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6826 from jskeet/fix-custom-options
Avoid NullReferenceException when accessing CustomOptions
parents
129a7c87
7282f29c
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
24 additions
and
8 deletions
+24
-8
CustomOptionsTest.cs
.../src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs
+16
-0
EnumDescriptor.cs
csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
+1
-1
EnumValueDescriptor.cs
csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
+1
-1
FieldDescriptor.cs
csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
+1
-1
FileDescriptor.cs
csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
+1
-1
MessageDescriptor.cs
csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
+1
-1
MethodDescriptor.cs
csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs
+1
-1
OneofDescriptor.cs
csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
+1
-1
ServiceDescriptor.cs
csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
+1
-1
No files found.
csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs
View file @
61d75cb8
...
...
@@ -41,6 +41,7 @@ using static Google.Protobuf.WireFormat;
using
static
UnitTest
.
Issues
.
TestProtos
.
ComplexOptionType2
.
Types
;
using
static
UnitTest
.
Issues
.
TestProtos
.
UnittestCustomOptionsProto3Extensions
;
using
static
UnitTest
.
Issues
.
TestProtos
.
DummyMessageContainingEnum
.
Types
;
using
Google.Protobuf.TestProtos
;
#pragma warning disable CS0618
...
...
@@ -177,6 +178,21 @@ namespace Google.Protobuf.Test.Reflection
AssertOption
(
new
Aggregate
{
S
=
"FieldAnnotation"
},
fieldOptions
.
TryGetMessage
,
Fieldopt
,
AggregateMessage
.
Descriptor
.
Fields
[
"fieldname"
].
GetOption
);
}
[
Test
]
public
void
NoOptions
()
{
var
fileDescriptor
=
UnittestProto3Reflection
.
Descriptor
;
var
messageDescriptor
=
TestAllTypes
.
Descriptor
;
Assert
.
NotNull
(
fileDescriptor
.
CustomOptions
);
Assert
.
NotNull
(
messageDescriptor
.
CustomOptions
);
Assert
.
NotNull
(
messageDescriptor
.
Fields
[
1
].
CustomOptions
);
Assert
.
NotNull
(
fileDescriptor
.
Services
[
0
].
CustomOptions
);
Assert
.
NotNull
(
fileDescriptor
.
Services
[
0
].
Methods
[
0
].
CustomOptions
);
Assert
.
NotNull
(
fileDescriptor
.
EnumTypes
[
0
].
CustomOptions
);
Assert
.
NotNull
(
fileDescriptor
.
EnumTypes
[
0
].
Values
[
0
].
CustomOptions
);
Assert
.
NotNull
(
TestAllTypes
.
Descriptor
.
Oneofs
[
0
].
CustomOptions
);
}
private
void
AssertOption
<
T
,
D
>(
T
expected
,
OptionFetcher
<
T
>
fetcher
,
Extension
<
D
,
T
>
extension
,
Func
<
Extension
<
D
,
T
>,
T
>
descriptorOptionFetcher
)
where
D
:
IExtendableMessage
<
D
>
{
T
customOptionsValue
;
...
...
csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
View file @
61d75cb8
...
...
@@ -129,7 +129,7 @@ namespace Google.Protobuf.Reflection
/// The (possibly empty) set of custom options for this enum.
/// </summary>
[
Obsolete
(
"CustomOptions are obsolete. Use GetOption"
)]
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
.
_extensions
?.
ValuesByNumber
);
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
?
.
_extensions
?.
ValuesByNumber
);
/// <summary>
/// Gets a single value enum option for this descriptor
...
...
csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
View file @
61d75cb8
...
...
@@ -74,7 +74,7 @@ namespace Google.Protobuf.Reflection
/// The (possibly empty) set of custom options for this enum value.
/// </summary>
[
Obsolete
(
"CustomOptions are obsolete. Use GetOption"
)]
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
.
_extensions
?.
ValuesByNumber
);
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
?
.
_extensions
?.
ValuesByNumber
);
/// <summary>
/// Gets a single value enum value option for this descriptor
...
...
csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
View file @
61d75cb8
...
...
@@ -299,7 +299,7 @@ namespace Google.Protobuf.Reflection
/// The (possibly empty) set of custom options for this field.
/// </summary>
[
Obsolete
(
"CustomOptions are obsolete. Use GetOption"
)]
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
.
_extensions
?.
ValuesByNumber
);
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
?
.
_extensions
?.
ValuesByNumber
);
/// <summary>
/// Gets a single value field option for this descriptor
...
...
csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
View file @
61d75cb8
...
...
@@ -542,7 +542,7 @@ namespace Google.Protobuf.Reflection
/// The (possibly empty) set of custom options for this file.
/// </summary>
[
Obsolete
(
"CustomOptions are obsolete. Use GetOption"
)]
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
.
_extensions
?.
ValuesByNumber
);
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
?
.
_extensions
?.
ValuesByNumber
);
/// <summary>
/// Gets a single value file option for this descriptor
...
...
csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
View file @
61d75cb8
...
...
@@ -261,7 +261,7 @@ namespace Google.Protobuf.Reflection
/// The (possibly empty) set of custom options for this message.
/// </summary>
[
Obsolete
(
"CustomOptions are obsolete. Use GetOption"
)]
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
.
_extensions
?.
ValuesByNumber
);
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
?
.
_extensions
?.
ValuesByNumber
);
/// <summary>
/// Gets a single value message option for this descriptor
...
...
csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs
View file @
61d75cb8
...
...
@@ -74,7 +74,7 @@ namespace Google.Protobuf.Reflection
/// The (possibly empty) set of custom options for this method.
/// </summary>
[
Obsolete
(
"CustomOptions are obsolete. Use GetOption"
)]
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
.
_extensions
?.
ValuesByNumber
);
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
?
.
_extensions
?.
ValuesByNumber
);
/// <summary>
/// Gets a single value method option for this descriptor
...
...
csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
View file @
61d75cb8
...
...
@@ -106,7 +106,7 @@ namespace Google.Protobuf.Reflection
/// The (possibly empty) set of custom options for this oneof.
/// </summary>
[
Obsolete
(
"CustomOptions are obsolete. Use GetOption"
)]
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
proto
.
Options
.
_extensions
?.
ValuesByNumber
);
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
proto
.
Options
?
.
_extensions
?.
ValuesByNumber
);
/// <summary>
/// Gets a single value oneof option for this descriptor
...
...
csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
View file @
61d75cb8
...
...
@@ -95,7 +95,7 @@ namespace Google.Protobuf.Reflection
/// The (possibly empty) set of custom options for this service.
/// </summary>
[
Obsolete
(
"CustomOptions are obsolete. Use GetOption"
)]
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
.
_extensions
?.
ValuesByNumber
);
public
CustomOptions
CustomOptions
=>
new
CustomOptions
(
Proto
.
Options
?
.
_extensions
?.
ValuesByNumber
);
/// <summary>
/// Gets a single value service option for this descriptor
...
...
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