dotnet / dotnet/macios

Add support for nullable out/ref parameters in the generator

Open
#4,826 4 comments 2 reactions 0 assignees View on GitHub
enhancement generator iOS macOS request-for-comments
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 13h
Merged PRs (30d)
96

Description

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

Example:

```objc
- (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):

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

would produce:

```csharp

// 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);
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.