2021-08-11 11:06:46 +03:00
|
|
|
using System;
|
[generator] Turn [Async] methods inside [Protocol] into extension methods
Partial fix for:
https://bugzilla.xamarin.com/show_bug.cgi?id=53076
We currently generate extension methods for optional members decorated
with [Async] inside a [Protocol] but we ignore the required methods
decorated with [Async]. This commit fixes this issue and we now
generate extension methods for required members.
Lets take the following API definition
```csharp
[Protocol]
interface MyFooProtocol {
[Abstract]
[Async]
[Export ("requiredMethod:completion:")]
void RequiredMethod (int arg1, Action<NSError> err);
[Async]
[Export ("optional:completion:")]
void OptionalMethod (int arg1, Action<NSError> err);
}
```
This generates:
```csharp
public static partial class MyFooProtocol_Extensions {
[CompilerGenerated]
public unsafe static void OptionalMethod (this IMyFooProtocol This, int arg1, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V0))]global::System.Action<NSError> err)
{
if (err == null)
throw new ArgumentNullException ("err");
BlockLiteral *block_ptr_err;
BlockLiteral block_err;
block_err = new BlockLiteral ();
block_ptr_err = &block_err;
block_err.SetupBlock (Trampolines.SDActionArity1V0.Handler, err);
global::ApiDefinition.Messaging.void_objc_msgSend_int_IntPtr (This.Handle, Selector.GetHandle ("optional:completion:"), arg1, (IntPtr) block_ptr_err);
block_ptr_err->CleanupBlock ();
}
[CompilerGenerated]
public unsafe static Task OptionalMethodAsync (this IMyFooProtocol This, int arg1)
{
var tcs = new TaskCompletionSource<bool> ();
This.OptionalMethod(arg1, (obj_) => {
if (obj_ != null)
tcs.SetException (new NSErrorException(obj_));
else
tcs.SetResult (true);
});
return tcs.Task;
}
[CompilerGenerated]
public unsafe static Task RequiredMethodAsync (this IMyFooProtocol This, int arg1)
{
var tcs = new TaskCompletionSource<bool> ();
This.RequiredMethod(arg1, (obj_) => {
if (obj_ != null)
tcs.SetException (new NSErrorException(obj_));
else
tcs.SetResult (true);
});
return tcs.Task;
}
}
```
Adds unit test
Build diff:
https://gist.github.com/dalexsoto/75290d1ffa1fdfb529cc30b9e66de5f2
2017-03-25 07:57:05 +03:00
|
|
|
|
|
|
|
using Foundation;
|
|
|
|
using ObjCRuntime;
|
|
|
|
|
|
|
|
namespace Bug53076Test {
|
|
|
|
[Protocol]
|
|
|
|
interface MyFooProtocol {
|
|
|
|
|
|
|
|
[Abstract]
|
|
|
|
[Async]
|
|
|
|
[Export ("requiredMethod:completion:")]
|
|
|
|
void RequiredMethod (int arg1, Action<NSError> err);
|
|
|
|
|
|
|
|
[Async]
|
|
|
|
[Export ("optional:completion:")]
|
|
|
|
void OptionalMethod (int arg1, Action<NSError> err);
|
|
|
|
|
|
|
|
[Abstract]
|
|
|
|
[Async]
|
|
|
|
[Export ("requiredReturnMethod:completion:")]
|
|
|
|
bool RequiredReturnMethod (int arg1, Action<NSError> err);
|
|
|
|
|
|
|
|
[Async]
|
|
|
|
[Export ("optionalReturn:completion:")]
|
|
|
|
bool OptionalReturnMethod (int arg1, Action<NSError> err);
|
|
|
|
|
|
|
|
[Abstract]
|
|
|
|
[Async (ResultTypeName = "RequiredReturnMethodObjResult")]
|
|
|
|
[Export ("requiredReturnMethodObj:completion:")]
|
2022-11-18 01:04:21 +03:00
|
|
|
bool RequiredReturnMethodObj (int arg1, Action<NSError, NSObject> err);
|
[generator] Turn [Async] methods inside [Protocol] into extension methods
Partial fix for:
https://bugzilla.xamarin.com/show_bug.cgi?id=53076
We currently generate extension methods for optional members decorated
with [Async] inside a [Protocol] but we ignore the required methods
decorated with [Async]. This commit fixes this issue and we now
generate extension methods for required members.
Lets take the following API definition
```csharp
[Protocol]
interface MyFooProtocol {
[Abstract]
[Async]
[Export ("requiredMethod:completion:")]
void RequiredMethod (int arg1, Action<NSError> err);
[Async]
[Export ("optional:completion:")]
void OptionalMethod (int arg1, Action<NSError> err);
}
```
This generates:
```csharp
public static partial class MyFooProtocol_Extensions {
[CompilerGenerated]
public unsafe static void OptionalMethod (this IMyFooProtocol This, int arg1, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V0))]global::System.Action<NSError> err)
{
if (err == null)
throw new ArgumentNullException ("err");
BlockLiteral *block_ptr_err;
BlockLiteral block_err;
block_err = new BlockLiteral ();
block_ptr_err = &block_err;
block_err.SetupBlock (Trampolines.SDActionArity1V0.Handler, err);
global::ApiDefinition.Messaging.void_objc_msgSend_int_IntPtr (This.Handle, Selector.GetHandle ("optional:completion:"), arg1, (IntPtr) block_ptr_err);
block_ptr_err->CleanupBlock ();
}
[CompilerGenerated]
public unsafe static Task OptionalMethodAsync (this IMyFooProtocol This, int arg1)
{
var tcs = new TaskCompletionSource<bool> ();
This.OptionalMethod(arg1, (obj_) => {
if (obj_ != null)
tcs.SetException (new NSErrorException(obj_));
else
tcs.SetResult (true);
});
return tcs.Task;
}
[CompilerGenerated]
public unsafe static Task RequiredMethodAsync (this IMyFooProtocol This, int arg1)
{
var tcs = new TaskCompletionSource<bool> ();
This.RequiredMethod(arg1, (obj_) => {
if (obj_ != null)
tcs.SetException (new NSErrorException(obj_));
else
tcs.SetResult (true);
});
return tcs.Task;
}
}
```
Adds unit test
Build diff:
https://gist.github.com/dalexsoto/75290d1ffa1fdfb529cc30b9e66de5f2
2017-03-25 07:57:05 +03:00
|
|
|
|
|
|
|
[Async (ResultTypeName = "RequiredReturnMethodObjResult")]
|
|
|
|
[Export ("optionalReturnObj:completion:")]
|
2022-11-18 01:04:21 +03:00
|
|
|
bool OptionalReturnMethodObj (int arg1, Action<NSError, NSObject> err);
|
[generator] Turn [Async] methods inside [Protocol] into extension methods
Partial fix for:
https://bugzilla.xamarin.com/show_bug.cgi?id=53076
We currently generate extension methods for optional members decorated
with [Async] inside a [Protocol] but we ignore the required methods
decorated with [Async]. This commit fixes this issue and we now
generate extension methods for required members.
Lets take the following API definition
```csharp
[Protocol]
interface MyFooProtocol {
[Abstract]
[Async]
[Export ("requiredMethod:completion:")]
void RequiredMethod (int arg1, Action<NSError> err);
[Async]
[Export ("optional:completion:")]
void OptionalMethod (int arg1, Action<NSError> err);
}
```
This generates:
```csharp
public static partial class MyFooProtocol_Extensions {
[CompilerGenerated]
public unsafe static void OptionalMethod (this IMyFooProtocol This, int arg1, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V0))]global::System.Action<NSError> err)
{
if (err == null)
throw new ArgumentNullException ("err");
BlockLiteral *block_ptr_err;
BlockLiteral block_err;
block_err = new BlockLiteral ();
block_ptr_err = &block_err;
block_err.SetupBlock (Trampolines.SDActionArity1V0.Handler, err);
global::ApiDefinition.Messaging.void_objc_msgSend_int_IntPtr (This.Handle, Selector.GetHandle ("optional:completion:"), arg1, (IntPtr) block_ptr_err);
block_ptr_err->CleanupBlock ();
}
[CompilerGenerated]
public unsafe static Task OptionalMethodAsync (this IMyFooProtocol This, int arg1)
{
var tcs = new TaskCompletionSource<bool> ();
This.OptionalMethod(arg1, (obj_) => {
if (obj_ != null)
tcs.SetException (new NSErrorException(obj_));
else
tcs.SetResult (true);
});
return tcs.Task;
}
[CompilerGenerated]
public unsafe static Task RequiredMethodAsync (this IMyFooProtocol This, int arg1)
{
var tcs = new TaskCompletionSource<bool> ();
This.RequiredMethod(arg1, (obj_) => {
if (obj_ != null)
tcs.SetException (new NSErrorException(obj_));
else
tcs.SetResult (true);
});
return tcs.Task;
}
}
```
Adds unit test
Build diff:
https://gist.github.com/dalexsoto/75290d1ffa1fdfb529cc30b9e66de5f2
2017-03-25 07:57:05 +03:00
|
|
|
}
|
2017-11-20 16:55:16 +03:00
|
|
|
|
|
|
|
[BaseType (typeof (NSObject))]
|
2022-11-18 01:04:21 +03:00
|
|
|
interface RequiredReturnMethodObjResult { }
|
[generator] Turn [Async] methods inside [Protocol] into extension methods
Partial fix for:
https://bugzilla.xamarin.com/show_bug.cgi?id=53076
We currently generate extension methods for optional members decorated
with [Async] inside a [Protocol] but we ignore the required methods
decorated with [Async]. This commit fixes this issue and we now
generate extension methods for required members.
Lets take the following API definition
```csharp
[Protocol]
interface MyFooProtocol {
[Abstract]
[Async]
[Export ("requiredMethod:completion:")]
void RequiredMethod (int arg1, Action<NSError> err);
[Async]
[Export ("optional:completion:")]
void OptionalMethod (int arg1, Action<NSError> err);
}
```
This generates:
```csharp
public static partial class MyFooProtocol_Extensions {
[CompilerGenerated]
public unsafe static void OptionalMethod (this IMyFooProtocol This, int arg1, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V0))]global::System.Action<NSError> err)
{
if (err == null)
throw new ArgumentNullException ("err");
BlockLiteral *block_ptr_err;
BlockLiteral block_err;
block_err = new BlockLiteral ();
block_ptr_err = &block_err;
block_err.SetupBlock (Trampolines.SDActionArity1V0.Handler, err);
global::ApiDefinition.Messaging.void_objc_msgSend_int_IntPtr (This.Handle, Selector.GetHandle ("optional:completion:"), arg1, (IntPtr) block_ptr_err);
block_ptr_err->CleanupBlock ();
}
[CompilerGenerated]
public unsafe static Task OptionalMethodAsync (this IMyFooProtocol This, int arg1)
{
var tcs = new TaskCompletionSource<bool> ();
This.OptionalMethod(arg1, (obj_) => {
if (obj_ != null)
tcs.SetException (new NSErrorException(obj_));
else
tcs.SetResult (true);
});
return tcs.Task;
}
[CompilerGenerated]
public unsafe static Task RequiredMethodAsync (this IMyFooProtocol This, int arg1)
{
var tcs = new TaskCompletionSource<bool> ();
This.RequiredMethod(arg1, (obj_) => {
if (obj_ != null)
tcs.SetException (new NSErrorException(obj_));
else
tcs.SetResult (true);
});
return tcs.Task;
}
}
```
Adds unit test
Build diff:
https://gist.github.com/dalexsoto/75290d1ffa1fdfb529cc30b9e66de5f2
2017-03-25 07:57:05 +03:00
|
|
|
}
|