The Wayback Machine - https://web.archive.org/web/20211117181120/https://github.com/dotnet/aspnetcore/issues/38479
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blazor] CascadingTypeParameter problem #38479

Open
daniel-p-tech opened this issue Nov 17, 2021 · 0 comments
Open

[Blazor] CascadingTypeParameter problem #38479

daniel-p-tech opened this issue Nov 17, 2021 · 0 comments

Comments

Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
@daniel-p-tech
Copy link

@daniel-p-tech daniel-p-tech commented Nov 17, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment