2012-04-07 32 views
0

我將Mono嵌入到Objective-c編寫的MacOSX應用程序中。在Objective-C項目中嵌入Mono:如何處理返回的List <>

我正在訪問一個C#lib(DDL),它只包含一堆返回不同類型的靜態方法。 到目前爲止,我能順利拿到返回的整型,雙和字符串,但我無法檢索返回數組...

對於爲例,這裏是我如何檢索一個int:

MonoDomain *domain = mono_jit_init("TestDomain"); 

NSBundle* mainBundle = [NSBundle mainBundle]; 
NSString* dll = [mainBundle pathForResource:@"TestLib86" ofType:@"dll"]; 

MonoAssembly* assembly = mono_domain_assembly_open(domain, [dll UTF8String]); 

MonoImage* image = mono_assembly_get_image(assembly); 

// Get INTEGER 

// get a method handle to whatever you like 
const char* descAsString = "MiniLib86.Show:GetInt()"; 
MonoMethodDesc* description = mono_method_desc_new(descAsString,TRUE); 
MonoMethod* method = mono_method_desc_search_in_image(description, image); 

// call it 
void* args[0]; 
MonoObject *result = mono_runtime_invoke(method, NULL, args, NULL);  
int int_result = *(int*)mono_object_unbox (result); 

// See the result in log 
NSLog(@"int result %i", int_result); 

的方法在C#中返回一個List如下所示:

public static List<int> GetListInt() 
{ 
    return new System.Collections.Generic.List<int>{1,2,3,4,5}; 
} 

任何幫助將非常感激!

回答

0

看一看mono_runtime_invoke_array

相關問題