Given the following classes:
public class MyList<T> : IList<T>, ICloneable
{ ... }
public class PinList : MyList<SomeClass>, ICloneable, IEquatable<PinList>
{ ... }
Why wont this work?
public void Main()
{
PinList pins = new PinList();
Method2(pins); // Does not work
List<string> strings = new List<string>();
Method2(strings); // WORKS
}
public void Method2(object obj)
{
// returns TRUE
obj.GetType().GetInterfaces().Any(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IList<>));
var things = ((IList)obj).Cast<object>().ToList();
// Unable to cast object of type 'PinList' to type 'System.Collections.IList'.
}
I've tried hard casting the obj to obj.GetType(), and I've looked on google to no avail.