Building a wrapper for an iOS library. So far so good. Except in a method
that returns an object. Method always returns NSObject instead. The same
story is in delegate that has an object parameter .

For example,TCConnection is defined in Monotouch binding project as 

 

//@interface TCConnection : NSObject 


    [BaseType (typeof(NSObject))]


    public  interface TCConnection 


    {





        [ExportAttribute("state")]


        int state {get;}





    //...


    }

 

class TCDevice is defined as follows

 

//@interface TCDevice : NSObject 


[BaseType (typeof(NSObject))]


public interface TCDevice


{


    [ExportAttribute("initWithCapabilityToken:delegate:")]


    IntPtr Constructor(String token, TCDeviceDelegate d);





    [Export("connect:delegate:")]


    TCConnection Connect([NullAllowed] NSDictionary param, [NullAllowed]
TCConnectionDelegate del);





}

 


 
<http://stackoverflow.com/questions/12450057/how-to-define-that-a-function-r
eturns-an-object-when-building-binding-for-a-ios> 

Building a wrapper for an iOS library. So far so good. Except in a method
that returns an object. Method always returns NSObject instead. The same
story is in delegate that has an object parameter .

For example,TCConnection is defined in Monotouch binding project as 

//@interface TCConnection : NSObject 


      [BaseType (typeof(NSObject))]


      public  interface TCConnection 


      {


  


          [ExportAttribute("state")]


          int state {get;}


  


      //...


      }

class TCDevice is defined as follows

//@interface TCDevice : NSObject 


  [BaseType (typeof(NSObject))]


  public interface TCDevice


  {


      [ExportAttribute("initWithCapabilityToken:delegate:")]


      IntPtr Constructor(String token, TCDeviceDelegate d);


  


      [Export("connect:delegate:")]


      TCConnection Connect([NullAllowed] NSDictionary param, [NullAllowed]
TCConnectionDelegate del);


  


  }

Everything is compiled nicely to a dll. When I use the dll in other project,
I call

 

MyTCDeviceDelegate d=new MyTCDeviceDelegate();


String token="XXXXX";


TCDevice dev=new TCDevice(token, d); 


TCConnection conn=dev.Connect(null,null);

 

The last line always throws Invalid Cast exception.It looks like the method
returns NSObject.

What I am missing here?

 

_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to