Open naasking opened 5 days ago
I want to define an endpoint that I can ensure only returns either a razor slice or a redirect. In ASP.NET I would normally do something like this:
public static Results<IRazorSliceHttpResult, RedirectHttpResult> Hello() => Results.Extensions.RazorSlice<MyApp.Slices.Hello, Model>(new Mode());
However, Results<T0, T1> constructs instances only via an implicit user-defined conversion. Since Results.Extensions.RazorSlice returns an interface and user-defined implicit conversions do not work on interfaces in C#, this pattern appears to be literally impossible with Razor Slices at the moment.
It could be made compatible by changing Results.Extensions.RazorSlice to return a non-interface type. If RazorSliceHttpResultWrapper could inherit from RazorSliceHttpResult, then that would work as the return type.
To workaround this I basically had to replicate the RazorSliceHttpResultWrapper and all of the supporting logic into a custom wrapper type.
I want to define an endpoint that I can ensure only returns either a razor slice or a redirect. In ASP.NET I would normally do something like this:
However, Results<T0, T1> constructs instances only via an implicit user-defined conversion. Since Results.Extensions.RazorSlice returns an interface and user-defined implicit conversions do not work on interfaces in C#, this pattern appears to be literally impossible with Razor Slices at the moment.
It could be made compatible by changing Results.Extensions.RazorSlice to return a non-interface type. If RazorSliceHttpResultWrapper could inherit from RazorSliceHttpResult, then that would work as the return type.