Xamarin.iOS binding projects do not support custom marshalling.
But I don't think you need it:
[BaseType (typeof (NSObject))]
public partial interface MarshalTest {
[Export ("initWithMarshal:")]
IntPtr Constructor (ref Marshal3D marshal);
[Export ("initWithMarshals:num:")]
IntPtr Constructor (Marshal3D[] marshals, int numCoord);
[Export ("addMarshal:")]
void AddMarshal (ref Marshal3D marshal);
[Export ("addMarshals:num:")]
void AddMarshals (Marshal3D[] marshals, int numCoord);
[Export ("getMarshals:")]
[Internal]
int GetMarshals (IntPtr getMarshals);
// ...
}
However to support GetMarshals nicely, you'll have to add a custom binding (this is typically done in the StructsAndEnums.cs file):
public partial class MarshalTest : NSObject {
public unsafe Marshal3D [] GetMarshals () {
var count = // how many are there? there's no API to fetch this in your sample
var array = new Marshal3D [count];
fixed (Marshal3D* ptr = &array[0])
GetMarshals ((IntPtr) ptr);
return array;
}
}
[Updated to answer second set of questions]
For the constructor, I think this will work:
ApiDefinition.cs
[BaseType (typeof (NSObject))] public partial interface MarshalTest { [Export ("initWithMarshals:num:")] [Internal] IntPtr Constructor (IntPtr marshals, int numCoord); }
Extra.cs
public partial class MarshalTest : NSObject { public MarshalTest (Marshal3D[] marshals, int numCoord) : this (GetPointer (marshals), numCoord) { } static IntPtr GetPointer (Marshal3D[] marshals) { fixed (Marshal3D* ptr = &marshals[0]) return (IntPtr) ptr; }
}
You're right, it's expecting a pointer to a array. Try this instead:
ApiDefinition.cs
[BaseType (typeof (NSObject))] public partial interface MarshalTest { [Export ("getMarshals:")] [Internal] int GetMarshals (ref IntPtr getMarshals); }
Extra.cs
public partial class MarshalTest : NSObject { public unsafe Marshal3D [] GetMarshals () { var ptr = IntPtr.Zero; var count = this.StoredNumber (); var array = new Marshal3D [count]; GetMarshals (ref ptr); unsafe { Marshal3D* ptr3d = (Marshal3D *) ptr; for (int i = 0; i < count; i++) array [i] = *ptr3d++; } return array; } }