[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();
}
Please sign in to leave a comment.
Sean,
filed http://www.jetbrains.net/jira/browse/RSRP-37635
Friendly,
Dmitry
--
Dmitry Lomov
Technical Lead/Software Architect
JetBrains, Inc.
"Develop With Pleasure!"
Thanks Dmitry :)
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:
>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(); >>]]> }
Ignore previous, I'm on crack or something. :)