Click here to Skip to main content
15,913,933 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Project can not be opended Pin
Luc Pattyn3-Apr-08 14:43
sitebuilderLuc Pattyn3-Apr-08 14:43 
GeneralRe: Project can not be opended Pin
mpavas3-Apr-08 15:03
mpavas3-Apr-08 15:03 
QuestionHow Do I Do a Build Using Visual Web Developer Express 2005? Pin
Jeff Solochek2-Apr-08 19:56
Jeff Solochek2-Apr-08 19:56 
GeneralTrigger a controls event handler manually Pin
NumberXaero2-Apr-08 12:47
NumberXaero2-Apr-08 12:47 
GeneralRe: Trigger a controls event handler manually Pin
Luc Pattyn3-Apr-08 14:07
sitebuilderLuc Pattyn3-Apr-08 14:07 
Questionhow can I see the interbal details of an assembly Pin
sujithkumarsl2-Apr-08 3:10
sujithkumarsl2-Apr-08 3:10 
AnswerRe: how can I see the interbal details of an assembly Pin
Simon P Stevens2-Apr-08 3:22
Simon P Stevens2-Apr-08 3:22 
GeneralInheritance Pin
bort_verdon1-Apr-08 22:00
bort_verdon1-Apr-08 22:00 
Hello

We have a base class (A1) with derived classes (A2).
The base class has a collection of another class (X1).
Class X1 also is the base class for a few other classes (X2).

We know that the only type of X objects that will exist in A2 are types X2.

Currently X1 returns the list of A1
As X2 is derived from X1 it also exposes the list of A1
So when looping through this collection in A2 each object needs to be cast to type X2

What we are after is a method to avoid this casting
We cant use override as the return type doesnt match x1
We cant use new as it is not possible to cast the underlying collection to List<x2>
Weve tried many other ideas none of which have helped

Is there any suggestions about what we could try?
Or do we have to always cast the X1 objects to X2.

The code is along the lines of

<br />
public class X1 {<br />
    //Various Properties<br />
    public string propQ;<br />
    public string propW;<br />
}<br />
<br />
public class X2 : X1 {<br />
    //More Properties<br />
    public string propE;<br />
    public string propR;<br />
}<br />
<br />
public class A1 {<br />
    //Various Properties<br />
    public string prop1 {<br />
        get {return _prop1;}<br />
        set {_prop1 = value;}<br />
    }<br />
    protected string _prop1 = "";<br />
<br />
    //Collections<br />
    public List<x1> colOfX {<br />
        get {return _x;}<br />
    }<br />
    protected List<x1> _x = new List<x1>();<br />
}<br />
<br />
public class A2 : A1 {<br />
    //Other Properties<br />
    public string prop2 {<br />
        get {<br />
            return "";<br />
        }<br />
        set {<br />
        }<br />
    }<br />
<br />
    //Override Collections<br />
/*<br />
    //Wont compile because return type is different (even though it is a descendant)<br />
    public override List<x2> colOfX {<br />
        get {<br />
            return _x;<br />
        }<br />
    }<br />
    //Wont compile because _x cant be cast to List<x2><br />
    public new List<x2> colOfX {<br />
        get {<br />
            return _x;<br />
        }<br />
    }<br />
 */<br />
}<br />
</x2></x2></x2></x1></x1></x1>

BTW: Apologies for the crap class/property names
GeneralRe: Inheritance Pin
Simon P Stevens1-Apr-08 23:18
Simon P Stevens1-Apr-08 23:18 
GeneralRe: Inheritance Pin
bort_verdon2-Apr-08 13:13
bort_verdon2-Apr-08 13:13 
GeneralOutOfMemoryException Pin
Rei Miyasaka31-Mar-08 20:37
Rei Miyasaka31-Mar-08 20:37 
GeneralRe: OutOfMemoryException Pin
led mike1-Apr-08 4:46
led mike1-Apr-08 4:46 
GeneralRe: OutOfMemoryException Pin
Luc Pattyn1-Apr-08 5:41
sitebuilderLuc Pattyn1-Apr-08 5:41 
GeneralRe: OutOfMemoryException Pin
Rei Miyasaka1-Apr-08 15:26
Rei Miyasaka1-Apr-08 15:26 
GeneralRe: OutOfMemoryException Pin
led mike2-Apr-08 4:39
led mike2-Apr-08 4:39 
GeneralRe: OutOfMemoryException Pin
Rei Miyasaka2-Apr-08 7:26
Rei Miyasaka2-Apr-08 7:26 
GeneralRe: OutOfMemoryException Pin
led mike2-Apr-08 8:22
led mike2-Apr-08 8:22 
GeneralRe: OutOfMemoryException Pin
Dave Kreskowiak2-Apr-08 9:37
mveDave Kreskowiak2-Apr-08 9:37 
GeneralWindows service error .. installutil.exe .. Pin
rajesh.tycoon31-Mar-08 17:00
rajesh.tycoon31-Mar-08 17:00 
GeneralRe: Windows service error .. installutil.exe .. Pin
led mike1-Apr-08 4:44
led mike1-Apr-08 4:44 
GeneralSOAP Deserialization Pin
lverre31-Mar-08 3:30
lverre31-Mar-08 3:30 
GeneralRe: SOAP Deserialization Pin
led mike31-Mar-08 4:33
led mike31-Mar-08 4:33 
QuestionTo mention single strong name key in an XML file for all prjoects Pin
Mushtaque Nizamani31-Mar-08 1:19
Mushtaque Nizamani31-Mar-08 1:19 
GeneralRe: To mention single strong name key in an XML file for all prjoects Pin
led mike31-Mar-08 4:34
led mike31-Mar-08 4:34 
GeneralUnable to load proxy class at runtime when using "Add Web Reference..." Pin
bwilhite30-Mar-08 11:58
bwilhite30-Mar-08 11:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.