summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Claude Manoli <jc@manoli.net>2017-02-05 08:02:14 +0100
committerGitHub <noreply@github.com>2017-02-05 08:02:14 +0100
commit18ac3030df9b90e217bdc14646385c438c5966e9 (patch)
treed3041217d3fa9232aa060121b6e2c7ddda825947
parentf5299fba8206d5b9e4398796bec13f20e53eeac4 (diff)
downloadswig-18ac3030df9b90e217bdc14646385c438c5966e9.tar.gz
Replace ICollection with IEnumerable<T>
Adding a constructor that accepts IEnumerable<T> avoids the boxing and unboxing overhead of the original constructor, when the type parameter is a value type. This also allows passing IList<T>, which does not implement ICollection (ironically the generated type implements IList<T>). Kept the original constructor for backward compatibility, but replaced ICollection with IEnumerable for added flexibility.
-rw-r--r--Lib/csharp/std_vector.i10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i
index 12220aa57..8cddf4c5d 100644
--- a/Lib/csharp/std_vector.i
+++ b/Lib/csharp/std_vector.i
@@ -26,13 +26,21 @@
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...)
%typemap(csinterfaces) std::vector< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n";
%proxycode %{
- public $csclassname(global::System.Collections.ICollection c) : this() {
+ public $csclassname(global::System.Collections.IEnumerable c) : this() {
if (c == null)
throw new global::System.ArgumentNullException("c");
foreach ($typemap(cstype, CTYPE) element in c) {
this.Add(element);
}
}
+
+ public $csclassname(global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)> c) : this() {
+ if (c == null)
+ throw new global::System.ArgumentNullException("c");
+ foreach ($typemap(cstype, CTYPE) element in c) {
+ this.Add(element);
+ }
+ }
public bool IsFixedSize {
get {