[Mono-list] Generic class and mono_class_from_name

2015-03-12 Thread mimi
I embedded Mono runtime 3.12 in my QT c++ app on Os x 10.8.5 and try to get
generic class in my c++ app.

Case 1:

c#
namespace TestDictionary
{
public class Class1
{
public Dictionarystring,object DictionaryField;

public static void Dump (Dictionary string, object dictionary)
{
Console.WriteLine(Dump called\n);
}
public static void Main()
{
Console.WriteLine(Class1 Main called!\n);
}
}
}

c++
MonoClass* classDictionary = NULL;
classDictionary = mono_class_from_name(image, TestDictionary,
Class1);

I compiled TestDictionary.exe and classDictionary is non-NULL.


Case 2:

c#
namespace TestDictionary
{
public class Class1
{
public Dictionarystring,object DictionaryField;

public static void Dump (Dictionary string, object dictionary)
{
Console.WriteLine(Dump called\n);
}
}
}

namespace Playstkop.Toolbox
{
public class ToolboxFacade
{
  public static void Main()
  {
  Class1 testClass1 = new Class1();
  Console.WriteLine(ToolboxFacade Main called!!\n);
  }
}
}

c++
MonoClass* classDictionary = NULL;
classDictionary = mono_class_from_name(image, TestDictionary,
Class1);

I compiled TestDictionary.dll and Playstkop.Toolbox.exe. classDictionary
returns NULL. I digged into mono_class_from_name and found that the value of
'name' is 0x0 instead of Class1.

Locals  
assembly_idx@0x guint32
buf  \235§\013\001\000\000\000... char [1024]
class   0x0 MonoClass *
class@1 0x0 MonoClass *
class@2 @0x10bca9f00MonoClass
cols@0x0guint32 [5]
i   @0x int
idx @0x guint32
image   @0x10487fe00MonoImage
impl@0x guint32
len @0x int
loaded_image0x0 MonoImage *
module  0x0 MonoImage *
name   0x0  char *
name_space  TestDictionarychar *
nested  0x0 char *
nspace_table0x0 GHashTable *
pos @0x int
res @0x gboolean
t   0x0 MonoTableInfo *
token   0   guint32

This is the Locals when 'mono_class_from_name' returns: 

Locals  
assembly_idx@0x guint32
buf  ݯ\013\001\000\000\000@ú\... char [1024]
class   0x0 MonoClass *
class@1 0x0 MonoClass *
class@2 0x0 MonoClass *
cols@0x0guint32 [5]
i   @0x int
idx @0x guint32
image   0x0 MonoImage *
impl@0x guint32
len @0x int
loaded_image0x0 MonoImage *
module  0x0 MonoImage *
name0x0 char *
name_space  TestDictionarychar *
nested  0x0 char *
nspace_table0x0 GHashTable *
pos @0x int
res @0x gboolean
t   0x0 MonoTableInfo *
token   0   guint32

I go back to Case 1 and trace the method 'mono_class_from_name'. The value
of 'name' is also 0x0 (Surprised!).

Locals  
assembly_idx@0x guint32
buf  ý§\013\001\000\000@...   char [1024]
class   0x0 MonoClass *
class@1 0x0 MonoClass *
class@2 @0x10bcaff00MonoClass
cols@0x0guint32 [5]
i   @0x int
idx @0x guint32
image   @0x1068a3c00MonoImage
impl@0x guint32
len @0x int
loaded_image0x0 MonoImage *
module  0x0 MonoImage *
name   0x0  char *
name_space  TestDictionarychar *
nested  0x0 char *
nspace_table0x0 GHashTable *
pos @0x int
res @0x gboolean
t   0x0 MonoTableInfo *
token   0   guint32

However, when 

Re: [Mono-list] Generic class and mono_class_from_name

2015-03-11 Thread Edward Ned Harvey (mono)
 From: mono-list-boun...@lists.ximian.com [mailto:mono-list-
 boun...@lists.ximian.com] On Behalf Of mimi
 
 public Dictionarystring,object DictionaryField;

Unrelated to your actual question, it's recommended that you make public things 
Properties instead of Fields.
public Dictionarystring,object FooDict { get; set; }

This is basically because if you later need to add something like a set 
accessor for data scrubbing or validation checking, by having a property, you 
have not changed your interface.  If you change a field to a property, it's 
considered a breaking change - meaning - all your code and all the code that 
depends on your code needs to be recompiled and the binaries are not compatible 
with each other.  If you want to know more, you can google for properties vs 
fields.  Lots of people have written things about it.
___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] Generic class and mono_class_from_name

2015-03-11 Thread Robert Jordan

On 10.03.2015 20:24, mimi wrote:


c++
 MonoClass* classDictionary = NULL;
 classDictionary = mono_class_from_name(image, TestDictionary,
Class1);

I compiled TestDictionary.dll and Playstkop.Toolbox.exe. classDictionary
returns NULL. I digged into mono_class_from_name and found that the value of
'name' is 0x0 instead of Class1.



You're passing the wrong `image' to mono_class_from_name.
If you want TestDictionary.Class1 from TestDictionary.dll,
then you must use the image of TestDictionary.dll.

Robert


___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] Generic class and mono_class_from_name

2015-03-11 Thread mimi
@EdwardNedHarvey: Thank you very much for your important advice.
@RobertJordan: Sorry, I misunderstood the process. I though when I load the
main assembly into the domain, I can access all classes and methods of other
assemblies referred by main assembly from the image of main assembly. Just
tried and works fine. Thanks for the help!



--
View this message in context: 
http://mono.1490590.n4.nabble.com/Generic-class-and-mono-class-from-name-tp4665611p4665620.html
Sent from the Mono - General mailing list archive at Nabble.com.
___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list