Support runtime casting for types with dynamic
as a generic parameter
#6837
Replies: 4 comments 6 replies
-
This error happens both with the "covariance" and "contravariance", switching |
Beta Was this translation helpful? Give feedback.
-
If we're offering the feature here that would be a bug. Bool and dynamic should not have a variance relationship. |
Beta Was this translation helpful? Give feedback.
-
Variance in C# only works when the conversion "does nothing", i.e. the converted object is the same as the original one. When it comes to Specifically:
I don't see any of this changing. |
Beta Was this translation helpful? Give feedback.
-
@CyrusNajmabadi @svick that's why I put "covariance" in quotes, I'm just talking about converting between |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using
dynamic
as a generic parameter for a given type, it seems natural that this can be slotted in for any other generic parameter on that type.In current C#:
For .NET 7, caching of methods was improved and IDE0200 (Remove unnecessary lambda expression) was introduced. For this reason, I tried adding this in my scenarios represented above, and received an error.
I know everyone hates
dynamic
. Adding functionality along these lines might bring more eyes ondynamic
and tempt people to use it.As someone who works with it at my company, I understand more than most. But this seems like a completely natural scenario we would love to use, for both code quality and whatever performance gain we can muster.
Edit: The original title talked about "covariance" between types like M and M, I was drawing a spiritual parallel but the new title better reflects the actual proposal.
Beta Was this translation helpful? Give feedback.
All reactions