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
3f826a6d
Commit
3f826a6d
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 method for Any.Is (#5207)
parent
2b0a18b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
AnyTest.cs
csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs
+13
-0
AnyPartial.cs
csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs
+11
-0
No files found.
csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs
View file @
3f826a6d
...
...
@@ -140,5 +140,18 @@ namespace Google.Protobuf.WellKnownTypes
var
message
=
new
TestWellKnownTypes
{
AnyField
=
new
Any
()
};
Assert
.
AreEqual
(
"{ \"anyField\": { \"@type\": \"\", \"@value\": \"\" } }"
,
message
.
ToString
());
}
[
Test
]
public
void
IsWrongType
()
{
var
any
=
Any
.
Pack
(
SampleMessages
.
CreateFullTestAllTypes
());
Assert
.
False
(
any
.
Is
(
TestOneof
.
Descriptor
));
}
public
void
IsRightType
()
{
var
any
=
Any
.
Pack
(
SampleMessages
.
CreateFullTestAllTypes
());
Assert
.
True
(
any
.
Is
(
TestAllTypes
.
Descriptor
));
}
}
}
csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs
View file @
3f826a6d
...
...
@@ -67,6 +67,17 @@ namespace Google.Protobuf.WellKnownTypes
return
lastSlash
==
-
1
?
""
:
typeUrl
.
Substring
(
lastSlash
+
1
);
}
/// <summary>
/// Returns a bool indictating whether this Any message is of the target message type
/// </summary>
/// <param name="descriptor">The descriptor of the message type</param>
/// <returns><c>true</c> if the type name matches the descriptor's full name or <c>false</c> otherwise</returns>
public
bool
Is
(
MessageDescriptor
descriptor
)
{
ProtoPreconditions
.
CheckNotNull
(
descriptor
,
nameof
(
descriptor
));
return
GetTypeName
(
TypeUrl
)
==
descriptor
.
FullName
;
}
/// <summary>
/// Unpacks the content of this Any message into the target message type,
/// which must match the type URL within this Any message.
...
...
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