I have this razor generic component TModel with parameters of Expression
now when the parent component of the previous one gives TModel type WorkOrder
the Expression
Code
DataGridComponent.razor.cs
public partial class DataGridComponent<TModel> : ComponentBase , IDisposable
where TModel : DbModel
{
[Parameter]
public Expression<Func<TModel, object>>[] Properties { get; set; }
}
SomeViewModel.razor
<div>
<DataGridComponent TModel="WorkOrder" Orderable="true" Indexable="true"
Properties="new Expression<Func<WorkOrder, object>>[] { <--------- Syntax Error
a=>a.Location.LocationType,
a=>a.MainService
}"></DataGridComponent>
</div>
--Cannot covert .... WorkOrder to ... TModel
further investigation..
it works if it is not an array of expression
one expression worked w/o errors...
even more...
it worked fine if it is List<> but not array...
this is a workaround i guess :)
Thanks for the issue report @mRmEEeZ. This looks like a bug in code generation when arrays are involved with generic components. Here's a much simpler reproduction of the problem:
```C#
public partial class TestComponent
{
[Parameter]
public IList
[Parameter]
public TModel[] Prop2 { get; set; }
}
```razor
@{
var x = new[] { "Hello", "World" };
}
<TestComponent TModel="string" Prop1="x" Prop2="x"></DataGridComponent>
The generated code for the IList property does the correct type inference, but the array one does not perform substitution:
// IList
__builder.AddAttribute(5, "Prop1", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<System.Collections.Generic.IList<WorkOrder>>(
// Array
__builder.AddAttribute(6, "Prop2", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<TModel[]>(
@mRmEEeZ given that using IList works for you, I'll recommend using that.
Yay !
first time i issue a real issue :p
Most helpful comment
Yay !
first time i issue a real issue :p