diff options
author | Jean-Claude Manoli <jc@manoli.net> | 2017-02-05 08:02:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-05 08:02:14 +0100 |
commit | 18ac3030df9b90e217bdc14646385c438c5966e9 (patch) | |
tree | d3041217d3fa9232aa060121b6e2c7ddda825947 | |
parent | f5299fba8206d5b9e4398796bec13f20e53eeac4 (diff) | |
download | swig-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.i | 10 |
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 { |