[API Proposal]: Rethink and implement use case of CS0416 #6923
Replies: 4 comments 5 replies
-
I'd also like to add my support to this idea. We have had to go to pretty significant lengths to work around this in the LibraryImport source generator and other interop source generator for our user-defined marshalling logic, and it would be very nice to be able to avoid propagating that design elsewhere. |
Beta Was this translation helpful? Give feedback.
-
Can you flesh out the example so it's something compilable except for the one thing you'd ike to work? The title and OP should actually refer to the language rules, not compiler error codes. There's no way to know what this is referring to in isolation. |
Beta Was this translation helpful? Give feedback.
-
In order for this work, we'd need to have a way to encode the
In other words, the type is encoded as a UTF-8 encoded byte array. This string has no ability to refer to several things, including the |
Beta Was this translation helpful? Give feedback.
-
Examaple that otherwise compiles public class TestAttrAttribute<T> : Attribute
{
T someItem;
}
public class Foo<T>
{
[TestAttr<T>()]
public void Test(T item)
{
}
} |
Beta Was this translation helpful? Give feedback.
-
Background and motivation
Currently using a generic inside an attribute is an illegal move and results in CS0416, this has been established very very long ago to keep the compiler simple. Given the current move to more reusable, readable code we should try to reevaluate the problem.
This currently required other hacky ways to pass the info or sometimes destroys a particular usecase completely.
API Proposal
[Attr(typeof(List))]
API Usage
Alternative Designs
No response
Risks
Change to the compiler, albeit being only additive
Beta Was this translation helpful? Give feedback.
All reactions