Assignment of native container types to generated types in C#
Mario Emmenlauer <[email protected]> Mon, 12 Sep 2022 17:11:06 +0200
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <[email protected]> |
Dear All,
I've just started with SWIG and followed the documentation to build
a few first examples. Everything works great!
Now I have a question: I can not use directly the native C# type in
a method signature that expects the generated type. Am I doing some-
thing wrong, or is that expected? I'm not too knowledgeable with C#
so I have a hard time understanding what is even missing - the
assignment operator maybe?
The native method expects a `const std::vector<std::string>&`. I name
this `StringVector` in the interface.
This code illustrates the problem in C#:
string[] cData = { "Hello", "World", "äöü", "ß 是" };
IList<string> vStringList = new List<string>(cData);
var vInteropTestNativeWrapper = new InteropTestNativeWrapper();
// This does not compile, with error:
// Argument 1: cannot convert from 'System.Collections.Generic.IList<string>' to 'StringVector' [InteropTestManaged]
//vInteropTestNativeWrapper.setStringVector(vStringList);
// This compiles and works, but is a bit more cumbersome:
vInteropTestNativeWrapper.setStringVector(new StringVector(vStringList));
Is that to be expected, or is there some way in SWIG to use native
types and generated types interchangeable?
All the best,
Mario Emmenlauer
_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user