[Mono-osx] MonoMac [Target]

Miguel de Icaza miguel at novell.com
Mon Apr 26 16:07:39 EDT 2010


Hello,

I'm experimenting with how to generate various constructs from the header
> files.  Here is a common pattern:
>
> Inside AppKit\NSTextAttachment.cs there is this:
> @interface NSMutableAttributedString
> (NSMutableAttributedStringAttachmentConveniences)
> - (void)updateAttachmentsFromPath:(NSString *)path;
> @end
>

I have seen this before;   As you noticed we used the [Target] attribute on
the first parameter to tell the generator about this use case.

Instead of adding the methods to the base class (in this case
NSMutableAttributedString) we put these in the place where they actually
need to be (the NSTextAttachment).

This is not always possible.   There are some extensions that are not really
attached to any class and are really extensions to the base class and have
no dependency to the new class or framework other than the fact that they
are being defined there.   In those cases we went with the approach of
sticking those into the base class.   Luckily there are not too many of
these.


> Which I tried to bind like this (ignoring making the C# method name
> better):
>   //- (void)updateAttachmentsFromPath:(NSString *)path; [Export
> ("updateAttachmentsFromPath:")] void UpdateAttachmentsFromPath ([Target]
> NSMutableAttributedString obj, NSString path);
>

This look ok, and needs to go into the NSTextAttachment interface.

(I do no think the generated code for when IsDirectBinding == false is
> correct.  But that is a side issue.)
>

I would like to hear about this ;-)


> Is this the correct binding?  I would of course have to call:
> NSTextAttachment textAttachment;
> textAttachment.UpdateAttachmentsFromPath(attributedStringObj, path);
>
> Or would I rather call:
> attributedStringObj.UpdateAttachmentsFromPath(path);
>

The former.


> In my parser I have the ability of adding this method directly on
> NSMutableAttributedString, the 2nd example.  Another option would be to
> create an extension method to NSMutableAttributedString when parsing
> NSTextAttachment.  Maybe the generator should create:
>
> public static class NSMutableAttributedStringAttachmentConveniences
> {
>    public static void UpdateAttachmentsFromPath(this
> NSMutableAttributedString obj, NSString path)
>    { ...
>    }
> }
>
> So I know how to modify the parser what is the preferred solution?
>

This is an intriguing approach;   I like that it is mapping into C#
extension methods.

Since the binding is still on its early stages, we have the freedom to adopt
this approach if it makes sense.   Notice that in this case, I am not sure
that there is a benefit, but it might help in other cases.

Miguel.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20100426/6d28df31/attachment.html 


More information about the Mono-osx mailing list