[Mono-osx] MonoMac: ClassHandle issue

Duane Wandless duane at wandless.net
Sat Jul 10 13:52:54 EDT 2010


I had originally tried obj.GetType().Name but that returned the base class
name (NSViewController) not the class name.  Which is how I went down the
ClassHandle path.

Note GetType().Name works in a pure C# project.  But in a mixed
managed/unmanaged world it does not.

>From ObjC:
MyViewController : NSViewController

MyViewController* v;
[csharpObject setMyDelegate:v];

In C#:
[Export("setMyDelegate:")]
void SetMyDelegate(NSObject obj)
{
   Console.WriteLine(obj.GetType().Name); <=== returns NSViewController

But if I use Geoff's recommendation of:
new Class(Messaging.IntPtr_objc_msgSend(o.Handle,
Selector.GetHandle("class"))).Name

I get the correct class name.

I can log a bug if needed (and worth it).
Duane



On Sat, Jul 10, 2010 at 12:14 PM, Miguel de Icaza <miguel at novell.com> wrote:

> Hello Geoff,
>
>      I did not pay close enough attention to the sample.   I  was thinking
> that he was doing "myViewController.GetType ()" and not messing with the
> internals.
>
> Miguel.
>
> On Sat, Jul 10, 2010 at 12:09 PM, Geoff Norton <GNorton at novell.com> wrote:
>
>> Actually no, the issue here is he's using ClassHandle in a way that isn't
>> supported.  ClassHandle is used internally in the bindings to figure out if
>> we're a direct binding or not to do appropriate dispatch, it is NOT
>> analogous to [self class];  If you want [self class] you can do
>> Messaging.intptr_objc_msgSend (this.Handle, Selector.GetHandle ("class"))
>>
>> Maybe we should expose this in a seperate property?
>>
>> -g
>>
>> On 2010-07-10, at 11:56 AM, Miguel de Icaza wrote:
>>
>> Hello Duane,
>>
>>     Are you referencing monomac.dll, or are you compiling all its source
>> code directly into your app?
>>
>>     This problem happens if you try to put the MonoMac source code into
>> your project, instead of keeping it as a separate assembly.
>>
>> Miguel
>>
>> On Sat, Jul 10, 2010 at 10:04 AM, Duane Wandless <duane at wandless.net>wrote:
>>
>>> Here is a test case that shows the same issue I have with an Obj-C
>>> object.  In my real app the MyViewController object is created in obj-c.
>>>  But this test case shows the same issue.
>>>
>>> using System;
>>> using MonoMac.Foundation;
>>> using MonoMac.AppKit;
>>> using MonoMac.ObjCRuntime;
>>>
>>> namespace monoMain
>>> {
>>>     public class myApp
>>>     {
>>>         public static void Main()
>>>         {
>>>                 NSApplication.Init();
>>>                 MyViewController sv = new MyViewController();
>>>                 Console.WriteLine("class handle {0}",
>>> sv.ClassHandle.ToString("x"));
>>>                 Console.WriteLine("class name {0}", new
>>> Class(sv.ClassHandle).Name);
>>>                 Class kls = new Class("MyViewController");
>>>                 Console.WriteLine("kls handle {0}",
>>> kls.Handle.ToString("x"));
>>>                 Console.WriteLine("kls name {0}", kls.Name);
>>>         }
>>>     }
>>>
>>>     [Register("MyViewController")]
>>>     public class MyViewController : NSViewController
>>>     {
>>>         public MyViewController()  { }
>>>     }
>>> }
>>>
>>>
>>> In the output I get:
>>> class handle a0625e70
>>> class name NSViewController
>>> kls handle d5dbc0
>>> kls name MyViewController
>>>
>>> The desired output is to have MyViewController returned in both cases.
>>>  If I use NSView as the class it does work as expected.
>>>
>>> I modified Class.cs to print out additional info:
>>> Registering MyViewController : NSViewController / 0xa0625e70 0xd5dbc0
>>> Console.WriteLine ("Registering {0} : {1} / 0x{2} 0x{3}", name,
>>> parent_name, parent.ToString("x"), handle.ToString("x"));
>>>
>>> So when the MyViewController is created it appears that its ClassHandle
>>> is incorrectly set to its super class handle.  I did take it a step further
>>> and created MyViewController2 : MyViewController.  And when sv.ClassHandle
>>> is printed out it is NSViewController's handle.
>>>
>>> Thanks,
>>> Duane
>>>
>>>
>>> _______________________________________________
>>> Mono-osx mailing list
>>> Mono-osx at lists.ximian.com
>>> http://lists.ximian.com/mailman/listinfo/mono-osx
>>>
>>>
>> _______________________________________________
>> Mono-osx mailing list
>> Mono-osx at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-osx
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20100710/650a3728/attachment-0001.html 


More information about the Mono-osx mailing list