Generic type constraint: notabstract #102581
Replies: 3 comments 1 reply
-
I don't understand. Unless you want to create an instance of |
Beta Was this translation helpful? Give feedback.
-
This can be done by markign the type parameter with an attribute, and having an analyzer check that attribute is fulfilled at the generic instantiation point. |
Beta Was this translation helpful? Give feedback.
-
I can't Mark the type with an attribute. In the example I showed the type Base is a type that I don't own, and can't access. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
As per the title, I'm often confronted with the problem of not being able to constrain a generic parameter to a type that is not abstract. the new() constraint (which without being able to specify parameters, is about as useful as tits on a bull) doesn't work because I don't require a public parameter-less constructor. Passing an abstract type as a generic parameter when the type doesn't allow it shouldn't require a runtime check/error.
That's basically it it in a nutshell.
Beta Was this translation helpful? Give feedback.
All reactions