L
Lloyd Dupont
I try to test the interface implemented by a generic with the simple test
below.
What puzzle me is that all 4 test return false!
Any idea why is that and how to find the IList interface from the type?
-------------
using System;
using System.Collections;
using System.Collections.Generic;
// csc /nologo Class1.cs && Class1
public class Class1
{
public static void Main()
{
List<string> ls = new List<string>();
if(ls is IList)
{
Console.WriteLine("is IList(1): " +
ls.GetType().IsSubclassOf(typeof(IList)));
Console.WriteLine("is IList(2): " +
ls.GetType().IsAssignableFrom(typeof(IList)));
Console.WriteLine("is IList(3): " +
ls.GetType().IsInstanceOfType(typeof(IList)));
Console.WriteLine("is IList(4): " +
ls.GetType().IsDefined(typeof(IList), true));
}
}
}
below.
What puzzle me is that all 4 test return false!
Any idea why is that and how to find the IList interface from the type?
-------------
using System;
using System.Collections;
using System.Collections.Generic;
// csc /nologo Class1.cs && Class1
public class Class1
{
public static void Main()
{
List<string> ls = new List<string>();
if(ls is IList)
{
Console.WriteLine("is IList(1): " +
ls.GetType().IsSubclassOf(typeof(IList)));
Console.WriteLine("is IList(2): " +
ls.GetType().IsAssignableFrom(typeof(IList)));
Console.WriteLine("is IList(3): " +
ls.GetType().IsInstanceOfType(typeof(IList)));
Console.WriteLine("is IList(4): " +
ls.GetType().IsDefined(typeof(IList), true));
}
}
}