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
727c0dc1
Commit
727c0dc1
authored
Jul 12, 2017
by
Jean-Rémy Bancel
Committed by
Jon Skeet
Jul 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C#: Implement IReadOnlyDictionary<K,V> in MapField<K,V>
parent
9ab7c73f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
MapFieldTest.cs
csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
+16
-0
MapField.cs
csharp/src/Google.Protobuf/Collections/MapField.cs
+11
-0
No files found.
csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
View file @
727c0dc1
...
...
@@ -540,6 +540,22 @@ namespace Google.Protobuf.Collections
Assert
.
Throws
<
ArgumentException
>(()
=>
map
.
ToString
());
}
#if !NET35
[
Test
]
public
void
IDictionaryKeys_Equals_IReadOnlyDictionaryKeys
()
{
var
map
=
new
MapField
<
string
,
string
>
{
{
"foo"
,
"bar"
},
{
"x"
,
"y"
}
};
CollectionAssert
.
AreEquivalent
(((
IDictionary
<
string
,
string
>)
map
).
Keys
,
((
IReadOnlyDictionary
<
string
,
string
>)
map
).
Keys
);
}
[
Test
]
public
void
IDictionaryValues_Equals_IReadOnlyDictionaryValues
()
{
var
map
=
new
MapField
<
string
,
string
>
{
{
"foo"
,
"bar"
},
{
"x"
,
"y"
}
};
CollectionAssert
.
AreEquivalent
(((
IDictionary
<
string
,
string
>)
map
).
Values
,
((
IReadOnlyDictionary
<
string
,
string
>)
map
).
Values
);
}
#endif
private
static
KeyValuePair
<
TKey
,
TValue
>
NewKeyValuePair
<
TKey
,
TValue
>(
TKey
key
,
TValue
value
)
{
return
new
KeyValuePair
<
TKey
,
TValue
>(
key
,
value
);
...
...
csharp/src/Google.Protobuf/Collections/MapField.cs
View file @
727c0dc1
...
...
@@ -67,6 +67,9 @@ namespace Google.Protobuf.Collections
/// </para>
/// </remarks>
public
sealed
class
MapField
<
TKey
,
TValue
>
:
IDeepCloneable
<
MapField
<
TKey
,
TValue
>>,
IDictionary
<
TKey
,
TValue
>,
IEquatable
<
MapField
<
TKey
,
TValue
>>,
IDictionary
#if !NET35
,
IReadOnlyDictionary
<
TKey
,
TValue
>
#endif
{
// TODO: Don't create the map/list until we have an entry. (Assume many maps will be empty.)
private
readonly
Dictionary
<
TKey
,
LinkedListNode
<
KeyValuePair
<
TKey
,
TValue
>>>
map
=
...
...
@@ -548,6 +551,14 @@ namespace Google.Protobuf.Collections
}
#
endregion
#
region
IReadOnlyDictionary
explicit
interface
implementation
#if !NET35
IEnumerable
<
TKey
>
IReadOnlyDictionary
<
TKey
,
TValue
>.
Keys
=>
Keys
;
IEnumerable
<
TValue
>
IReadOnlyDictionary
<
TKey
,
TValue
>.
Values
=>
Values
;
#endif
#
endregion
private
class
DictionaryEnumerator
:
IDictionaryEnumerator
{
private
readonly
IEnumerator
<
KeyValuePair
<
TKey
,
TValue
>>
enumerator
;
...
...
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