[Mono-osx] How to pass nil?

kjpou kjpou at pt.lu
Sun Jul 31 05:29:10 EDT 2011


Eric

If the parameter you are passing can be Null as per the docs then the 
bindings should be changed to reflect that.

When you find the parameter that can be null you will have to specify 
[NullAllowed] for the parameter.

Example:

         [Export ("colorUsingColorSpaceName:")]
         NSColor UsingColorSpace ([NullAllowed] string colorSpaceName);

The parameter colorSpaceName can be pass a null value so the parameter 
is marked as [NullAllowed] in the method declaration.

For properties you can do the same thing.

Example:

         [Export ("target"), NullAllowed]
         NSObject Target { get; set; }

The Target property accepts null values so for the Property definition 
you specify the NullAllowed attribute in the Export.

Kenneth

On 7/31/11 4:53 AM, Eric J. M. Smith wrote:
> Greetings,
>
> Another newbie question about the MonoMac bindings.
>
> I've found that a couple of methods throw an "Argument cannot be null" error even though the Apple docs state that they should be able to take nil as an argument.  I take it that it is a limitation of the current MonoMac bindings.  Given that, what's the best way to deal with this?
>
> For some cases, the ugly solution of allocating a temporary object (e.g. :myWindow.OrderOut(new NSObject())") seems to work.  But for other methods, a nil parameter has a special significance in the API... what's the best practice for passing nil in those cases?
>
> Thanks,
>
> Eric Smith
> Tarkvara Design Inc.
> _______________________________________________
> Mono-osx mailing list
> Mono-osx at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-osx
>


More information about the Mono-osx mailing list