Skip to content

[Blazor] CascadingTypeParameter problem #38479

Closed
dotnet/razor-compiler
#44
@daniel-p-tech

Description

@daniel-p-tech

Hi,

I'm trying to refactor my existing components to use the newly introduced CascadingTypeParameter attribute but I'm running into compiler errors.

BlzTableGrid.razor (this is the main grid component)

@attribute [CascadingTypeParameter(nameof(TItem))]
@typeparam TItem

<CascadingValue Value="this" IsFixed="true">
    @ColumnsTemplate
</CascadingValue>
...

BlzTableGrid.razor.cs

public partial class BlzTableGrid<TItem> where TItem : class
{
    [Parameter]
    public RenderFragment ColumnsTemplate { get; set; }
...

BlzGridBaseColumn.cs

public abstract partial class BlzGridBaseColumn<TItem> : ComponentBase where TItem : class
{
    [CascadingParameter]
    internal BlzTableGrid<TItem> Grid { get; set; }
...

BlzGridColumn.cs

public class BlzGridColumn<TItem> : BlzGridBaseColumn<TItem>, IGridFieldColumn<TItem> where TItem : class
{
    [Parameter]
    public string FieldName { get; set; }
...

TableGrid.razor (page consuming the grid component)

<BlzTableGrid
    TItem="WeatherForecastLookup"
    Items="WeatherForecasts"

    <ColumnsTemplate>
        <BlzGridEditColumn />
        <BlzGridDeleteColumn />
        <BlzGridViewColumn />
        <BlzGridColumn Title="Date" FieldName="@nameof(WeatherForecastLookup.Date)" Format="d" Width="10rem" />
...

I'm getting the following compiler error for what seems to be each column in TableGrid.razor page:

>C:\Projects\Blazor-Components\DemoApp\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Pages_Grid_TableGrid_razor.g.cs(563,29,563,34): error CS0449: The 'class', 'struct', 'unmanaged', 'notnull', and 'default' constraints cannot be combined or duplicated, and must be specified first in the constraints list.

Thank you for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:1Work that is critical for the release, but we could probably ship withoutbugThis issue describes a behavior which is not expected - a bug.feature-blazor-builtin-componentsFeatures related to the built in components we ship or could ship in the future

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions