Created
April 24, 2019 07:40
-
-
Save philippdolder/9b694995be3700d78c88792f6d6a69b2 to your computer and use it in GitHub Desktop.
Rider does not properly resolve more specific extension methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Rider | |
{ | |
using System.Collections.Generic; | |
using System.Linq; | |
using Xunit; | |
public class FaultyExtensionMethodResolution | |
{ | |
[Fact] | |
public void RiderResolvesWrongExtensionMethod() | |
{ | |
Container<object>[] collection = | |
{ | |
new Container<object>("hello"), | |
new Container<object>(5) | |
}; | |
IEnumerable<Container<string>> filtered = collection.OfType<string>(); | |
Assert.True(filtered.Count() == 1); | |
} | |
} | |
public class Container<T> | |
{ | |
public Container(T item) | |
{ | |
this.Item = item; | |
} | |
public T Item { get; } | |
} | |
public static class Extensions | |
{ | |
public static IEnumerable<Container<T>> OfType<T>(this Container<object>[] input) | |
{ | |
return input.Where(_ => _.Item.GetType() == typeof(T)).Select(_ => new Container<T>((T)_.Item)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment