Hi,
On 27.07.2015 19:53, Henry wrote:
Can anyone shed some light on the best way to enumerate a List<> using mono
embedding? I have a managed method that returns a List<>, I need to
enumerate this list in c code using mono embedding. I can't seem to find
any documentation or examples on this that provide a definitive answer on
how to do this. I've tried GetEnumerator and MoveNext, but there appears to
be some kind of issue with the generic implementations.
When it comes to accessing generic objects/classes, it's usually easier
to implement managed helper methods than doing all the footwork in
C/C++, e.g.:
static void int GetCount(List<string> list)
{
return list.Count;
}
static string GetElementAt(List<string> list, int pos)
{
return list[pos];
}
Manually (in C/C++), you'd need to obtain the method
"IEnumerable_GetEnumerator" (notice the rule of building
explicit interface method names) from the class of the list
object, something like that:
MonoObject *list = ...
MonoClass *klass = mono_object_get_class (list);
MonoMethod *method = mono_class_get_method_from_name(klass,
"IEnumerable_GetEnumerator", 0);
Then invoke the method to obtain the enumerator with
mono_runtime_invoke ().
Robert
_______________________________________________
Mono-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list