I'm trying to make a class that have 3 generic types and one of the types must inherit from that other class that have the other 2 generic types.
What I really need is that IForm inherits from FormComponent so it have all of it's methods implemented.
Form.razor
@typeparam TForm
@typeparam TModel
@typeparam TResult
<EditForm Model="@Model" OnValidSubmit="@HandleValidSubmit">
@ChildContent
</EditForm>
Form.razor.cs
public partial class Form<TForm, TModel, TResult>
where TForm : FormComponent<TModel, TResult>
{
[Parameter]
public TForm FormRef { get; set; }
[Parameter]
public EventCallback<TResult> OnValidSubmit { get; set; }
[Parameter]
public TModel Model { get; set; }
// ...
// some other properties
}
FormComponent.cs
public abstract class FormComponent<TModel, TResult> : BaseDomComponent
{
[CascadingParameter]
public TModel Model { get; set; }
public abstract TResult OnValidSubmit();
// ...
// some other properties
}
Code from where I use Form
<Form Model="@Entity" FormRef="@_formRef" OnValidSubmit="@HandleValidSubmit">
<XYZForm @ref="_formRef" />
<Button ButtonType="ButtonType.Submit">Submit</Button>
</Form>
But this gives me the error
Error CS0314 The type 'TForm' cannot be used as type parameter 'TForm' in the generic type or method 'Form< TForm, TModel, TResult >'. There is no boxing conversion or type parameter conversion from 'TForm' to 'Core.Web.Base.FormComponent< TModel, TResult >'
I searched this error in alot of places but didn't found any case where there was 3 generic types. I also read the docs but couldn't use that to solve my case.