[402] Generics Question

I have a situation similar to the following, which (incorrectly?) shows a
warning where shown in the method in Foo. However, my test code in Main()
shows it working correctly. Am I missing something?

Thanks

Sean

public class Person {}

public class Child : Person {}
public class Grandchild : Child {}

public class Uncle : Person {}

public interface IFoo
{
bool CanDo(U[] u) where U : Person; } public class Foo : IFoo where V : Person { bool IFoo.CanDo(U[] concrete) { // "The given expression is never of the provided type" under the expression below. return concrete is V[]; } } static void Main(string[] args) { //DelegateTest(); IFoo foo = new Foo]]>();

Grandchild[] grandchildren = new Grandchild[0];
Console.WriteLine(foo.CanDo(grandchildren)); // True

Uncle[] uncles = new Uncle[0];
Console.WriteLine(foo.CanDo(uncles)); // False

Console.ReadLine();
}


4 comments
Comment actions Permalink

Sean,
filed http://www.jetbrains.net/jira/browse/RSRP-37635

Friendly,
Dmitry

public class Person {}
public class Child : Person {}
public class Grandchild : Child {}
public class Uncle : Person {}
public interface IFoo
{
bool CanDo<U>(U[] u) where U : Person;
}
public class Foo<V> : IFoo where V : Person
{
bool IFoo.CanDo<U>(U[] concrete)
{
// "The given expression is never of the provided type" under
the expression below.
return concrete is V[];
}
}
static void Main(string[] args)
{
//DelegateTest();
IFoo foo = new Foo<Child>();
Grandchild[] grandchildren = new Grandchild[0];
Console.WriteLine(foo.CanDo(grandchildren)); // True
Uncle[] uncles = new Uncle[0];
Console.WriteLine(foo.CanDo(uncles)); // False
Console.ReadLine();
}

--
Dmitry Lomov
Technical Lead/Software Architect
JetBrains, Inc.
"Develop With Pleasure!"


0
Comment actions Permalink

Thanks Dmitry :)


0
Comment actions Permalink


I think you can close that issue. It's not a ReSharper bug, it's an
error in the code.

"return concrete is V[];" always returns bool. I'm sure you meant
"as". :)

- Casey


On Thu, 22 Mar 2007 10:57:22 +0000 (UTC), Dmitry Lomov (JetBrains)
<dmitry.lomov@jetbrains.com> wrote:

Sean,

>filed http://www.jetbrains.net/jira/browse/RSRP-37635
>
>Friendly,
>Dmitry
>
>> public class Person {}
>> public class Child : Person {}
>> public class Grandchild : Child {}
>> public class Uncle : Person {}
>> public interface IFoo
>> {
>> bool CanDo(U[] u) where U : Person; >> } >> public class Foo : IFoo where V : Person >> { >> bool IFoo.CanDo(U[] concrete) >> { >> // "The given expression is never of the provided type" under >> the expression below. >> return concrete is V[]; >> } >> } >> static void Main(string[] args) >> { >> //DelegateTest(); >> IFoo foo = new Foo(); >> Grandchild[] grandchildren = new Grandchild[0]; >> Console.WriteLine(foo.CanDo(grandchildren)); // True >> Uncle[] uncles = new Uncle[0]; >> Console.WriteLine(foo.CanDo(uncles)); // False >> Console.ReadLine(); >>]]> }

0
Comment actions Permalink


Ignore previous, I'm on crack or something. :)

0

Please sign in to leave a comment.