471,321 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

Re: Can I cast a generic list, or do I need another approach

On Jun 26, 2:11*pm, "RichB" <ri...@community.nospamwrote:
I have an abstract class Domain which is responsible for validation of my
model. All classes in the model inherit from Domain for operations such as
bool IsValid {get;}.
<snip>
However List<Addressand List<PhoneNumberdoes not cast to List<Domain>..
Is there a way to do this, or are there any other options other than
repeating the code?
Yes, there's a way to do it - you need to make the method generic:

public bool IsChildListValid<T>(List<TdomainList) where T : Domain
{
...
}

That should work with no problems.

Jon
Jun 27 '08 #1
1 1183

Thanks, just what I was after.

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:71**********************************@56g2000h sm.googlegroups.com...
On Jun 26, 2:11 pm, "RichB" <ri...@community.nospamwrote:
I have an abstract class Domain which is responsible for validation of my
model. All classes in the model inherit from Domain for operations such as
bool IsValid {get;}.
<snip>
However List<Addressand List<PhoneNumberdoes not cast to List<Domain>.
Is there a way to do this, or are there any other options other than
repeating the code?
Yes, there's a way to do it - you need to make the method generic:

public bool IsChildListValid<T>(List<TdomainList) where T : Domain
{
...
}

That should work with no problems.

Jon

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by ZenRhapsody | last post: by
4 posts views Thread by colson | last post: by
7 posts views Thread by =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post: by
15 posts views Thread by Lloyd Dupont | last post: by
2 posts views Thread by =?Utf-8?B?Unlhbg==?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.