If you want to work with them based on their concrete type - that sounds like a case for polymorphism... can you (in a partial class) add a few methods?
partial class Paragraph {
public abstract void Foo();
}
partial class ImageParagraph {
public override void Foo() {/*code*/}
}
partial class LinkListParagraph {
public override void Foo() {/*code*/}
}
Otherwise, if you want to filter the set, you can use the OfType
extension method - i.e.
foreach(var imgPara in obj.Paragraphs.OfType<ImageParagraph>())
{ ... }
Perhaps you could add properties for the above too (in the parent object) - i.e.
partial class Site {
public IQueryable<ImageParagraph> ImageParagraphs
{ get {return Paragraphs.OfType<ImageParagraph>(); }}
public IQueryable<LinkListParagraph> LinkListParagraphs
{ get {return Paragraphs.OfType<LinkListParagraph>(); }}
}
Marc Gravell
2009-02-12 09:59:38