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
5be01ee6
Commit
5be01ee6
authored
Aug 10, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement ICollection.CopyTo (using Array) for MapField views.
parent
3f45d7c1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
MapFieldTest.cs
csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
+14
-0
MapField.cs
csharp/src/Google.Protobuf/Collections/MapField.cs
+12
-1
No files found.
csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
View file @
5be01ee6
...
...
@@ -523,6 +523,20 @@ namespace Google.Protobuf.Collections
keys
.
CopyTo
(
array
,
1
);
CollectionAssert
.
AreEqual
(
new
[]
{
null
,
"foo"
,
"x"
,
null
},
array
);
}
// Just test keys - we know the implementation is the same for values
[
Test
]
public
void
NonGenericViewCopyTo
()
{
IDictionary
map
=
new
MapField
<
string
,
string
>
{
{
"foo"
,
"bar"
},
{
"x"
,
"y"
}
};
ICollection
keys
=
map
.
Keys
;
// Note the use of the Array type here rather than string[]
Array
array
=
new
string
[
4
];
Assert
.
Throws
<
ArgumentException
>(()
=>
keys
.
CopyTo
(
array
,
3
));
Assert
.
Throws
<
ArgumentOutOfRangeException
>(()
=>
keys
.
CopyTo
(
array
,
-
1
));
keys
.
CopyTo
(
array
,
1
);
CollectionAssert
.
AreEqual
(
new
[]
{
null
,
"foo"
,
"x"
,
null
},
array
);
}
[
Test
]
public
void
KeysContains
()
...
...
csharp/src/Google.Protobuf/Collections/MapField.cs
View file @
5be01ee6
...
...
@@ -735,7 +735,18 @@ namespace Google.Protobuf.Collections
public
void
CopyTo
(
Array
array
,
int
index
)
{
throw
new
NotImplementedException
();
if
(
index
<
0
)
{
throw
new
ArgumentOutOfRangeException
(
"arrayIndex"
);
}
if
(
index
+
Count
>=
array
.
Length
)
{
throw
new
ArgumentException
(
"Not enough space in the array"
,
"array"
);
}
foreach
(
var
item
in
this
)
{
array
.
SetValue
(
item
,
index
++);
}
}
}
}
...
...
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