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
46f8a798
Commit
46f8a798
authored
Oct 30, 2015
by
Jan Tattermusch
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #905 from jskeet/wrapper-clear
Fix clearing wrapper type fields with reflection.
parents
a74e912a
f5a0a7fe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
2 deletions
+12
-2
WrappersTest.cs
...p/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
+10
-0
FieldDescriptor.cs
csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
+1
-1
SingleFieldAccessor.cs
csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs
+1
-1
No files found.
csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
View file @
46f8a798
...
...
@@ -345,5 +345,15 @@ namespace Google.Protobuf.WellKnownTypes
var
message
=
TestWellKnownTypes
.
Parser
.
ParseFrom
(
stream
);
Assert
.
AreEqual
(
6
,
message
.
Int32Field
);
}
[
Test
]
public
void
ClearWithReflection
()
{
// String and Bytes are the tricky ones here, as the CLR type of the property
// is the same between the wrapper and non-wrapper types.
var
message
=
new
TestWellKnownTypes
{
StringField
=
"foo"
};
TestWellKnownTypes
.
Descriptor
.
Fields
[
TestWellKnownTypes
.
StringFieldFieldNumber
].
Accessor
.
Clear
(
message
);
Assert
.
IsNull
(
message
.
StringField
);
}
}
}
csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
View file @
46f8a798
...
...
@@ -197,7 +197,7 @@ namespace Google.Protobuf.Reflection
}
/// <summary>
/// Returns
the type of the field.
/// Returns the type of the field.
/// </summary>
public
FieldType
FieldType
{
...
...
csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs
View file @
46f8a798
...
...
@@ -61,7 +61,7 @@ namespace Google.Protobuf.Reflection
// TODO: Validate that this is a reasonable single field? (Should be a value type, a message type, or string/ByteString.)
object
defaultValue
=
typeof
(
IMessage
).
IsAssignableFrom
(
clrType
)
?
null
descriptor
.
FieldType
==
FieldType
.
Message
?
null
:
clrType
==
typeof
(
string
)
?
""
:
clrType
==
typeof
(
ByteString
)
?
ByteString
.
Empty
:
Activator
.
CreateInstance
(
clrType
);
...
...
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