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
930db675
Commit
930db675
authored
Jul 21, 2019
by
Sydney Acksman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert changes for FieldPresenceAccessor
parent
29141f48
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
59 deletions
+52
-59
FieldAccessTest.cs
...rp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
+44
-44
MessageExtensions.cs
csharp/src/Google.Protobuf/MessageExtensions.cs
+2
-2
IFieldAccessor.cs
csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
+5
-12
SingleFieldAccessor.cs
csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs
+1
-1
No files found.
csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
View file @
930db675
...
...
@@ -35,8 +35,8 @@ using Proto2 = Google.Protobuf.TestProtos.Proto2;
using
NUnit.Framework
;
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
static
Google
.
Protobuf
.
TestProtos
.
Proto2
.
UnittestExtensions
;
namespace
Google.Protobuf.Reflection
...
...
@@ -86,8 +86,8 @@ namespace Google.Protobuf.Reflection
var
dictionary
=
(
IDictionary
)
fields
[
TestMap
.
MapStringStringFieldNumber
].
Accessor
.
GetValue
(
mapMessage
);
Assert
.
AreEqual
(
mapMessage
.
MapStringString
,
dictionary
);
Assert
.
AreEqual
(
"value1"
,
dictionary
[
"key1"
]);
}
}
[
Test
]
public
void
GetValue_IncorrectType
()
{
...
...
@@ -97,29 +97,29 @@ namespace Google.Protobuf.Reflection
}
[
Test
]
public
void
HasValue_Proto3
()
{
IMessage
message
=
SampleMessages
.
CreateFullTestAllTypes
();
var
fields
=
message
.
Descriptor
.
Fields
;
Assert
.
Throws
<
InvalidOperationException
>(()
=>
(
fields
[
TestProtos
.
TestAllTypes
.
SingleBoolFieldNumber
].
Accessor
as
IFieldPresenceAccessor
).
HasValue
(
message
));
public
void
HasValue_Proto3
()
{
IMessage
message
=
SampleMessages
.
CreateFullTestAllTypes
();
var
fields
=
message
.
Descriptor
.
Fields
;
Assert
.
Throws
<
InvalidOperationException
>(()
=>
fields
[
TestProtos
.
TestAllTypes
.
SingleBoolFieldNumber
].
Accessor
.
HasValue
(
message
));
}
[
Test
]
public
void
HasValue
()
{
IMessage
message
=
new
Proto2
.
TestAllTypes
();
var
fields
=
message
.
Descriptor
.
Fields
;
var
accessor
=
fields
[
Proto2
.
TestAllTypes
.
OptionalBoolFieldNumber
].
Accessor
as
IFieldPresenceAccessor
;
Assert
.
False
(
accessor
.
HasValue
(
message
));
accessor
.
SetValue
(
message
,
true
);
Assert
.
True
(
accessor
.
HasValue
(
message
));
accessor
.
Clear
(
message
);
Assert
.
False
(
accessor
.
HasValue
(
message
));
public
void
HasValue
()
{
IMessage
message
=
new
Proto2
.
TestAllTypes
();
var
fields
=
message
.
Descriptor
.
Fields
;
var
accessor
=
fields
[
Proto2
.
TestAllTypes
.
OptionalBoolFieldNumber
].
Accessor
;
Assert
.
False
(
accessor
.
HasValue
(
message
));
accessor
.
SetValue
(
message
,
true
);
Assert
.
True
(
accessor
.
HasValue
(
message
));
accessor
.
Clear
(
message
);
Assert
.
False
(
accessor
.
HasValue
(
message
));
}
[
Test
]
public
void
SetValue_SingleFields
()
{
...
...
@@ -146,8 +146,8 @@ namespace Google.Protobuf.Reflection
};
Assert
.
AreEqual
(
expected
,
message
);
}
}
[
Test
]
public
void
SetValue_SingleFields_WrongType
()
{
...
...
@@ -190,8 +190,8 @@ namespace Google.Protobuf.Reflection
oneof
.
Accessor
.
Clear
(
message
);
Assert
.
AreEqual
(
TestProtos
.
TestAllTypes
.
OneofFieldOneofCase
.
None
,
message
.
OneofFieldCase
);
}
}
[
Test
]
public
void
Clear
()
{
...
...
@@ -243,26 +243,26 @@ namespace Google.Protobuf.Reflection
}
[
Test
]
public
void
GetExtensionValue
()
{
var
message
=
SampleMessages
.
CreateFullTestAllExtensions
();
// test that the reflector works, since the reflector just runs through IExtendableMessage
Assert
.
AreEqual
(
message
.
GetExtension
(
OptionalBoolExtension
),
Proto2
.
TestAllExtensions
.
Descriptor
.
FindFieldByNumber
(
OptionalBoolExtension
.
FieldNumber
).
Accessor
.
GetValue
(
message
));
public
void
GetExtensionValue
()
{
var
message
=
SampleMessages
.
CreateFullTestAllExtensions
();
// test that the reflector works, since the reflector just runs through IExtendableMessage
Assert
.
AreEqual
(
message
.
GetExtension
(
OptionalBoolExtension
),
Proto2
.
TestAllExtensions
.
Descriptor
.
FindFieldByNumber
(
OptionalBoolExtension
.
FieldNumber
).
Accessor
.
GetValue
(
message
));
}
[
Test
]
public
void
GetRepeatedExtensionValue
()
{
// check to make sure repeated accessor uses GetOrRegister
var
message
=
new
Proto2
.
TestAllExtensions
();
Assert
.
IsNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
Assert
.
IsNotNull
(
Proto2
.
TestAllExtensions
.
Descriptor
.
FindFieldByNumber
(
RepeatedBoolExtension
.
FieldNumber
).
Accessor
.
GetValue
(
message
));
Assert
.
IsNotNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
message
.
ClearExtension
(
RepeatedBoolExtension
);
Assert
.
IsNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
public
void
GetRepeatedExtensionValue
()
{
// check to make sure repeated accessor uses GetOrRegister
var
message
=
new
Proto2
.
TestAllExtensions
();
Assert
.
IsNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
Assert
.
IsNotNull
(
Proto2
.
TestAllExtensions
.
Descriptor
.
FindFieldByNumber
(
RepeatedBoolExtension
.
FieldNumber
).
Accessor
.
GetValue
(
message
));
Assert
.
IsNotNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
message
.
ClearExtension
(
RepeatedBoolExtension
);
Assert
.
IsNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
}
}
}
csharp/src/Google.Protobuf/MessageExtensions.cs
View file @
930db675
...
...
@@ -183,7 +183,7 @@ namespace Google.Protobuf
}
else
if
(
f
.
FieldType
==
FieldType
.
Message
||
f
.
FieldType
==
FieldType
.
Group
)
{
if
(
(
f
.
Accessor
as
IFieldPresenceAccessor
)
.
HasValue
(
message
))
if
(
f
.
Accessor
.
HasValue
(
message
))
{
return
((
IMessage
)
f
.
Accessor
.
GetValue
(
message
)).
IsInitialized
();
}
...
...
@@ -194,7 +194,7 @@ namespace Google.Protobuf
}
else
if
(
f
.
IsRequired
)
{
return
(
f
.
Accessor
as
IFieldPresenceAccessor
)
.
HasValue
(
message
);
return
f
.
Accessor
.
HasValue
(
message
);
}
else
{
...
...
csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
View file @
930db675
...
...
@@ -58,6 +58,11 @@ namespace Google.Protobuf.Reflection
/// </summary>
object
GetValue
(
IMessage
message
);
/// <summary>
/// Indicates whether the field in the specified message is set. For proto3 fields, this throws an <see cref="InvalidOperationException"/>
/// </summary>
bool
HasValue
(
IMessage
message
);
/// <summary>
/// Mutator for single "simple" fields only.
/// </summary>
...
...
@@ -68,15 +73,4 @@ namespace Google.Protobuf.Reflection
/// <exception cref="InvalidOperationException">The field is not a "simple" field.</exception>
void
SetValue
(
IMessage
message
,
object
value
);
}
/// <summary>
/// Allows field presence to be checked reflectively. This is implemented for all single field accessors
/// </summary>
public
interface
IFieldPresenceAccessor
:
IFieldAccessor
{
/// <summary>
/// Indicates whether the field in the specified message is set. For proto3 fields, this throws an <see cref="InvalidOperationException"/>
/// </summary>
bool
HasValue
(
IMessage
message
);
}
}
\ No newline at end of file
csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs
View file @
930db675
...
...
@@ -39,7 +39,7 @@ namespace Google.Protobuf.Reflection
/// <summary>
/// Accessor for single fields.
/// </summary>
internal
sealed
class
SingleFieldAccessor
:
FieldAccessorBase
,
IFieldPresenceAccessor
internal
sealed
class
SingleFieldAccessor
:
FieldAccessorBase
{
// All the work here is actually done in the constructor - it creates the appropriate delegates.
// There are various cases to consider, based on the property type (message, string/bytes, or "genuine" primitive)
...
...
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