Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bgen] Improve the generated code for SmarEnum BindAs calls. #22323

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/bgen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2910,9 +2910,8 @@ void GetReturnsWrappers (MethodInfo mi, MemberInformation minfo, Type declaringT
var formattedReturnType = TypeManager.FormatType (minfo.type, mi.ReturnType);
if (mi.ReturnType == TypeCache.NSString) {
if (isNullable) {
print ("{0} retvaltmp;", NativeHandleType);
cast_a = "((retvaltmp = ";
cast_b = $") == IntPtr.Zero ? default ({formattedBindAsType}) : ({wrapper}Runtime.GetNSObject<{formattedReturnType}> (retvaltmp, {owns})!){suffix})";
cast_a = $"{wrapper}";
cast_b = $"{suffix}";
} else {
cast_a = $"{wrapper}Runtime.GetNSObject<{formattedReturnType}> (";
cast_b = $", {owns})!{suffix}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ internal static InvocationExpressionSyntax StringFromHandle (ImmutableArray<Argu
IdentifierName ("FromHandle").WithTrailingTrivia (Space)))
.WithArgumentList (argumentList);
}

/// <summary>
/// Generates a call to the NSArray.ArrayFromHandleFunc with the given arguments.
/// </summary>
Expand All @@ -189,14 +189,14 @@ internal static InvocationExpressionSyntax NSArrayFromHandleFunc (string returnT
// generate <returnType>
var genericsList = TypeArgumentList (
SingletonSeparatedList<TypeSyntax> (IdentifierName (returnType)));

// generate NSArray.ArrayFromHandleFunc<returnType> (arg1, arg2, arg3)
return InvocationExpression (
MemberAccessExpression (
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName ("NSArray"),
GenericName ("ArrayFromHandleFunc")
.WithTypeArgumentList(genericsList)
.WithTypeArgumentList (genericsList)
.WithTrailingTrivia (Space)))
.WithArgumentList (argumentList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ void StringFromHandleTests (ImmutableArray<ArgumentSyntax> arguments, string exp
var declaration = StringFromHandle (arguments);
Assert.Equal (expectedDeclaration, declaration.ToFullString ());
}
class TestDataNSArrayFromHandleFunc: IEnumerable<object []> {

class TestDataNSArrayFromHandleFunc : IEnumerable<object []> {
public IEnumerator<object []> GetEnumerator ()
{
yield return [
Expand All @@ -168,7 +168,7 @@ public IEnumerator<object []> GetEnumerator ()

IEnumerator IEnumerable.GetEnumerator () => GetEnumerator ();
}

[Theory]
[ClassData (typeof (TestDataNSArrayFromHandleFunc))]
void NSArrayFromHandleFuncTests (string returnType, ImmutableArray<ArgumentSyntax> arguments, string expectedDeclaration)
Expand Down
Loading