(This question, if it contradicts what I asked before, when switching from RectangleF [] to NSArray. See here: How to convert RectangleF [] to NSArray CGRects? )
I have a third-party library and bindings for it. One of the bindings returns an NSArray (note: this is NOT " NSArray* ", but a simple " NSArray "), so returning RectangleF[] instead of NSArray does not work / is supported by MonoTouch. Now I have a problem: how to convert the returned NSArray (from NSRect , which I know) back to RectangleF[] ?
If I go through NSArray:
for(uint i = 0; i < oHighlightAnnot.Rects.Count; ++i) { IntPtr ptrRect = oHighlightAnnot.Rects.ValueAt(i); var oObj = new NSObject(ptrRect); }
And check oObj, I see in the debugger that this is NSRect:
{NSRect: {{121.3672, 265.76123}, {192.09813, 288}}}
But then what? NSRect not displayed, and CGRect and RectangleF not inherited from NSObject . How to cast / convert back?
Here is the completion method:
public virtual NSArray Rects { [Export ("rects")] get { NSArray nSArray; if (this.IsDirectBinding) { nSArray = (NSArray)Runtime.GetNSObject (Messaging.IntPtr_objc_msgSend (base.get_Handle (), PSPDFHighlightAnnotation.selRects)); } else { nSArray = (NSArray)Runtime.GetNSObject (Messaging.IntPtr_objc_msgSendSuper (base.get_SuperHandle (), PSPDFHighlightAnnotation.selRects)); } base.MarkDirty (); this.__mt_Rects_var = nSArray; return nSArray; } [Export ("setRects:")] set { if (this.IsDirectBinding) { Messaging.void_objc_msgSend_IntPtr (base.get_Handle (), PSPDFHighlightAnnotation.selSetRects_, (value != null) ? value.get_Handle () : IntPtr.Zero); } else { Messaging.void_objc_msgSendSuper_IntPtr (base.get_SuperHandle (), PSPDFHighlightAnnotation.selSetRects_, (value != null) ? value.get_Handle () : IntPtr.Zero); } base.MarkDirty (); this.__mt_Rects_var = value; } }
source share