Re: (inheritance) problem with generic
- From: "Lau Lei Cheong" <leu_lc@xxxxxxxxxxxx>
- Date: Wed, 15 Jun 2005 10:16:20 +0800
Have you tried "Console.WriteLine(ls is IList)"?
If ls is castable to IList, the result of using "is" operator will be "true"
"Lloyd Dupont" <net.galador@ld> ¼¶¼g©ó¶l¥ó·s»D:ujbExxUcFHA.228@xxxxxxxxxxxxxxxxxxxxxxx
>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));
> }
> }
> }
>
>
.
- Follow-Ups:
- Re: (inheritance) problem with generic
- From: Lloyd Dupont
- Re: (inheritance) problem with generic
- References:
- (inheritance) problem with generic
- From: Lloyd Dupont
- (inheritance) problem with generic
- Prev by Date: (inheritance) problem with generic
- Next by Date: Re: (inheritance) problem with generic
- Previous by thread: (inheritance) problem with generic
- Next by thread: Re: (inheritance) problem with generic
- Index(es):
Relevant Pages
|
Loading