dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.58k stars 10.06k forks source link

Does not support the same tag component with multiple generic types in Blazor #26323

Open teacher-zhou opened 4 years ago

teacher-zhou commented 4 years ago

I defind the component like this as below

    public class MyComponent<T>: MyComponent<T,int>
    {
    }

    public class MyComponent<T1, T2> : ComponentBase
    {

    }

but I cannot just use the one generic type component in razor file

<MyComponent T="string"></MyComponent>

The message shows : Multiple components use tag MyComponent with red underline by VS error.

Further technical details

ghost commented 4 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

TanayParikh commented 3 years ago

Hi. Thanks for contacting us. While there hasn't been much community interest in this feature yet, I'm inclined to leave this open as it may be something we may want to revisit in the future.

gulbanana commented 3 years ago

I would certainly use the feature if it's added. At the moment in my codebase I have pairs of components named like

<DynamicFoo>
<Foo T="item">

where Dynamic is the one without a generic parameter, as a workaround

Dreamescaper commented 2 years ago

This certainly would be useful. If I have a generic component, I'd like to allow to omit generic parameter, and simply use object. I hoped to be able to create two components:

class MyComponent<T>
class MyComponent: MyComponent<object>

Another option would be to allow to provide default generic parameter, but that feels less "csharp-y".

JelleHissink commented 1 year ago

This affects also my code, as for some generic controls (list of checkboxes, I have items and values, sometimes however they TItem can be TValue, otherwise you have an required lambda to extract a TValue from an TItem. If that makes sense.

I would like to be able to make components that could be used in a maner like this:

<RadioButtonList Items=@items @bind-Selection=@selected />
<RadioButtonList Items=@items @bind-Selection=@selected ValueForItem="@((item) => item.Id)" />