Open lindexi opened 9 months ago
Moving to uno.extensions.
cc @dr1rrb
Thank you @Youssef1313
And sorry I do not open the issues in the right repo.
Hummm didn't saw that, interesting case.
I assume that since the out
parameter won't be used, you actually don't need to have a command for that Foo
method and it is public
only to be consumed by someone else. If so you can add the [Uno.Extensions.Reactive.Commands.Command(false)]
attribute on your method to prevent generation (and if you still need it as a command, you should be able to add an overload that does not have that out
parameter).
Thank you @dr1rrb
I think it would be helpful to have more tips.
Ok my suggestion was only to do that:
public void Foo() => Foo(out _); // Generates the command
[Uno.Extensions.Reactive.Commands.Command(false)]
public void Foo(out int n) => n = 10; // Only use the method
But I tested and it actually doesn't work neither, it will still generate invalid code :(
Then unfortunately for now I can only suggest you to avoid usage of the out
keyword (as well as in
and ref
) on public
and internal
methods (reminder: if your method is private
, nothing is generated for it).
So to workaround that issue in your example, you should do something like:
[Uno.Extensions.Reactive.Commands.Command(false)]
public int Foo()
{
return 10;
}
And if you need more than one return value, then you should use value tuples, e..g:
[Uno.Extensions.Reactive.Commands.Command(false)]
public (int myInt, string myStr) Foo()
{
return (10, "hello world");
}
Current behavior
Can not compile
Expected behavior
Build successfully
How to reproduce it (as minimally and precisely as possible)
In the generated binding code in UNO's MVU, specifically in BindableXxx.cs, ICommand command binding properties are generated for the XxxModel layer. For example, for the following method in XxxModel:
A corresponding
public global::Uno.Extensions.Reactive.IAsyncCommand Foo { get; private set; }
property is generated in BindableXxx.cs.However, when generating ICommand command bindings, the 'out' keyword is not added for 'out' parameters. As in the above code, the current code generation content is as follows:
This generated code does not comply with C# syntax and will cause the build to fail with error code CS1620.
The simplest demo to reproduce this issue can be found at: https://github.com/lindexi/lindexi_gd/tree/eeeb023df2f7ab638bafc29d56e1e62a3445cd29/UnoKearqeljikay
Workaround
No response
Works on UWP/WinUI
None
Environment
No response
NuGet package version(s)
Affected platforms
Build tasks
IDE
Visual Studio 2022
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
No response