Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- namespace InferenceBug
- {
- public class MyDictionary: IEnumerable<int>, IEnumerable<KeyValuePair<string, int>>
- {
- public MyDictionary()
- {
- _source = new Dictionary<string, int>();
- }
- private readonly IDictionary<string, int> _source;
- IEnumerator<KeyValuePair<string, int>> IEnumerable<KeyValuePair<string, int>>.GetEnumerator()
- {
- return _source.GetEnumerator();
- }
- IEnumerator<int> IEnumerable<int>.GetEnumerator()
- {
- return _source.Values.GetEnumerator();
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return _source.GetEnumerator();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- // one implementation of IEnumerable: works fine
- Test(new Dictionary<string, int>
- {
- ["A"] = 1,
- ["B"] = 2
- });
- // two implementations: fails
- Test(new MyDictionary());
- }
- private static void Test<T>(IEnumerable<KeyValuePair<string, T>> arg)
- {
- // does nothing
- }
- }
- }
Add Comment
Please, Sign In to add comment