Beef
Beef copied to clipboard
[Enhancement] Allow explict lambda parameter types
Example:
(String self) => { return self; }
Otherwise, it's impossible to make this compile without the casts:
[Comptime]
public static void EmitCode<F>()
where F : var
{
var invokeMethod = typeof(F).GetMethod("Invoke").Get();
Debug.WriteLine("CompTime");
Debug.WriteLine(invokeMethod.ReturnType.GetFullName(.. scope .()));
Debug.WriteLine(invokeMethod.GetParamType(0).GetFullName(.. scope .()));
Debug.WriteLine(invokeMethod.GetParamType(1).GetFullName(.. scope .()));
}
public static void Test1<F>(F func)
{
EmitCode<F>();
}
public static int Main(String[] args)
{
Test1(/*(delegate String(String, uint8))*/ (new (a, b) => { return a; }));
Test1(/*(function String(String, uint8))*/ ((a, b) => { return a; }));
return 0;
}
I just saw this: https://devblogs.microsoft.com/dotnet/welcome-to-csharp-10/ :
Starting with C# 10, however, if a lambda does not have such a “target type” we will try to compute one for you:
var parse = (string s) => int.Parse(s);
So I guess they beat us to that one.