Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am working on an assertion library, and I have some generic constraints which are fairly complicated, in order to chain calls, and only show methods relevant for the object they're asserting on.
I have an issue where I'm trying to create an extension method for a dictionary to assert that it contains a key.
For this method, I only really care about the type of
Key
for the dictionary. But to keep the generic information, I also need to expose a genericTValue
type, even though I don't care about that. This is where it starts falling apart, as thisTValue
type is causing my problems with inferring the usage.Here's my method:
Now because there is not
TValue
parameter being passed into that method, the compiler tells me it can't infer the type properly.However, you can see that this method is an extension method. So surely it already knows that it's working off of a
Dictionary<string, byte[]
object, so why do I need to tell it the types again? As far as I can see, it should already know every type available based off of the dictionary object that it has been passed?Because the compiler is now asking the user to pass the generic types in (and this obviously being a complicated generic constraint) it makes my library very unfriendly to use for users.
Edit:
Here's a much more simple constraint but still shows the compiler can't work it out:
Beta Was this translation helpful? Give feedback.
All reactions