Skip to content

Instantly share code, notes, and snippets.

@philippdolder
Created April 24, 2019 07:40
Show Gist options
  • Save philippdolder/9b694995be3700d78c88792f6d6a69b2 to your computer and use it in GitHub Desktop.
Save philippdolder/9b694995be3700d78c88792f6d6a69b2 to your computer and use it in GitHub Desktop.
Rider does not properly resolve more specific extension methods
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