dotnet / dotnet/roslyn

Feature Request : allow components to reuse tag if generics are different

Open
#85,610 2 comments 0 reactions 0 assignees View on GitHub
Area-Razor Area-Razor-Compiler Feature Request
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

Ok so, this is maybe super complex, i dont know.
i also dont know if this was discussed before, i didn't find an issue about it but could have overlooked?

Currently in C# you can have a class exist with different amount of generics and depending on the implementation/call of the class you get the different types.

```
public class TestClass
{
public TValue Value {get; set;}
public TSomething Something {get; set;}
}

public class TestClass : TestClass
{
...
}
```

in this case i use inheritance to have the one with 1 generic implement the multiple generics with a default type param of object.
this works fine in code too :
```
var optional = new TestClass(); //this gives me the test class of which is secretly
var full = new TestClass(); //this gives me the other, full control over the types
```

however, as soon as you try this trick in blazor...
`TestComponent.razor`:
```
@typeparam TValue
@typeparam TSomething

Hello!
```
`TestComponent.razor.cs`:
```
public class TestComponent : TestComponent
{

}

public partial class TestComponent
{

}
```

you will get a compilation error :
`error RZ9985: Multiple components use the tag 'TestComponent'. Components: TestComponent, TestComponent`

is this something that can never work or can be implemented? hard to implement? (in case i start digging into the compiler :p )
personally this would be used to allow for UI libraries to change components without major breaking changes

Thanks in advance!

Contributor guide

Open the contributing guide

Research direction

Reproduce the RZ9985 error using TestComponent.razor and TestComponent.razor.cs, then trace how the compiler identifies the two TestComponent generic arities. The work is done when both generic forms can coexist without the duplicate-tag error and the one- and two-parameter usages shown in the issue compile correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.