Skip to content

Add support for nullable out/ref parameters in the generator #4826

Description

@rolfbjarne

Nullable out/ref variables are annoying, because they can't be expressed with a single (nice) signature.

Example:

- (void)doSomething:(nullable CGRect *)rect;

I suggest adding generator support for generating multiple functions for this, by specifying the Nullable attribute on the out/ref argument (I'll stick with just ref in the sample to make it simpler, but it applies to both variations):

[Export ("doSomething:")]
void DoSomething ([Nullable] ref CGRect rect);

would produce:

// This is for subclassing & overriding the implementation.
[Export ("doSomething:")]
protected virtual void DoSomething (IntPtr rect)
{
    objc_msgSend (...);
}

// Two overloads with nicer signatures.
public void DoSomething ()
{
    return DoSomething (IntPtr.Zero);
}

public void DoSomething (ref CGRect rect)
{
    unsafe {
        fixed (void *refarg1 = &rect)
            DoSomething ((IntPtr) refarg1);
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThe issue or pull request is an enhancementgeneratorIssues affecting the generatoriOSIssues affecting iOSmacOSIssues affecting macOSrequest-for-commentsThe issue is a suggested idea seeking feedback

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions