From 18ac3030df9b90e217bdc14646385c438c5966e9 Mon Sep 17 00:00:00 2001 From: Jean-Claude Manoli Date: Sun, 5 Feb 2017 08:02:14 +0100 Subject: [PATCH] Replace ICollection with IEnumerable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding a constructor that accepts IEnumerable avoids the boxing and unboxing overhead of the original constructor, when the type parameter is a value type. This also allows passing IList, which does not implement ICollection (ironically the generated type implements IList). Kept the original constructor for backward compatibility, but replaced ICollection with IEnumerable for added flexibility. --- Lib/csharp/std_vector.i | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 {