What is the exception or compiler error you are getting?
Thank you,
Ryan Olshan
Website - http://www.StrongTypes.com <http://www.strongtypes.com/>
Group - http://groups.yahoo.com/group/StrongTypes
Blog - http://blogs.strongcoders.com/blogs/ryan/
_____
From: StrongTypes@yahoogroups.com [mailto:StrongTypes@yahoogroups.com] On
Behalf Of Santiago Perez
Sent: Thursday, June 01, 2006 11:10 AM
To: StrongTypes@yahoogroups.com
Subject: [StrongTypes] Casting a SortedList Generic Class to a generic Class
of base type.
Hello everyone, this is my first post so please bare with me.
I am trying to understand why I can't cast generic class to a class
of a base type. I have the following setup:
///////////////////////////////////////////////////////////////////
public class Personnel_List<T> :
ProjectCentral.GlobalObjects.PersistentObject_List<Person_Abs> where
T : Person_Abs, iPerson
{
}
public abstract class Person_Abs :
ProjectCentral.GlobalObjects.PersistentObject, Contacts.iPerson
{
}
public class Vendor_Person : Person
{
}
public class Contract_Person : Vendor_Person
{
////////////////////////////////////////////////
Ok so now I have a contract class that has a property Personnel_List
which is
/////////////////////////////////////////////////////////////
public class Contract :
ProjectCentral.GlobalObjects.PersistentObject, iContract
{
public
ProjectCentral.Contacts.Personnel_List<Contacts.Contract_Person>
Personnel_List
{
get
{ if (this._Personnel_List == null)
this._Personnel_List = new
Personnel_List<Contract_Person>();
return this._Personnel_List;
}
set
{
this.Personnel_List = value;
}
}
}
//////////////////////////////////////////////////////////////////
THen I have a usercontrol that I want to use everywhere to list
Personnel so I set up a property as follows:
//////////////////////////////////////////////////////////
public Personnel_List<Person> DataSource
{
get { return (Personnel_List<Person>)
grdPersonnel.DataSource; }
set {grdPersonnel.DataSource = value;}
}
////////////////////////////////////////////////////////////
So when I try to do this it bombs on me:
///////////////////////////////////////////////////////////////
UcPersonnelList1.DataSource = ((Contract)
this.ContractDetail1.DataSource).Personnel_List;
////////////////////////////////////////////////////////////
Even if I try this:
///////////////////////////////////////////////////////////////
UcPersonnelList1.DataSource = (Personnel_List<Person>)((Contract)
this.ContractDetail1.DataSource).Personnel_List;
////////////////////////////////////////////////////////////
ANy help would be greatly appreciated. My boss is starting to look
at me like I don't know what I'm doing.
SPONSORED LINKS
Object
<http://groups.yahoo.com/gads?t=ms&k=Object+oriented&w1=Object+oriented&w2=O
bject+oriented+design&w3=Object+oriented+language&w4=Object+oriented+trainin
g&w5=Object+oriented+methodology&w6=Object+oriented+tutorial&c=6&s=172&.sig=
uLqg2pfGRplGmMsp6kJtVQ> oriented Object
<http://groups.yahoo.com/gads?t=ms&k=Object+oriented+design&w1=Object+orient
ed&w2=Object+oriented+design&w3=Object+oriented+language&w4=Object+oriented+
training&w5=Object+oriented+methodology&w6=Object+oriented+tutorial&c=6&s=17
2&.sig=pGWYLp0sQpJs3JoBMlqbdA> oriented design Object
<http://groups.yahoo.com/gads?t=ms&k=Object+oriented+language&w1=Object+orie
nted&w2=Object+oriented+design&w3=Object+oriented+language&w4=Object+oriente
d+training&w5=Object+oriented+methodology&w6=Object+oriented+tutorial&c=6&s=
172&.sig=oMxENFA3eiv-nKTwqk3z6Q> oriented language
Object
<http://groups.yahoo.com/gads?t=ms&k=Object+oriented+training&w1=Object+orie
nted&w2=Object+oriented+design&w3=Object+oriented+language&w4=Object+oriente
d+training&w5=Object+oriented+methodology&w6=Object+oriented+tutorial&c=6&s=
172&.sig=WW87rn12Wb695fEwKFWRNg> oriented training Object
<http://groups.yahoo.com/gads?t=ms&k=Object+oriented+methodology&w1=Object+o
riented&w2=Object+oriented+design&w3=Object+oriented+language&w4=Object+orie
nted+training&w5=Object+oriented+methodology&w6=Object+oriented+tutorial&c=6
&s=172&.sig=ZfydFONc8Llu8PBIVAyRuQ> oriented methodology Object
<http://groups.yahoo.com/gads?t=ms&k=Object+oriented+tutorial&w1=Object+orie
nted&w2=Object+oriented+design&w3=Object+oriented+language&w4=Object+oriente
d+training&w5=Object+oriented+methodology&w6=Object+oriented+tutorial&c=6&s=
172&.sig=5RlQ7dXcE52DzP8Rq1Dbdg> oriented tutorial
_____
YAHOO! GROUPS LINKS
* Visit your group "StrongTypes
<http://groups.yahoo.com/group/StrongTypes> " on the web.
* To unsubscribe from this group, send an email to:
StrongTypes-unsubscribe@yahoogroups.com
<mailto:StrongTypes-unsubscribe@yahoogroups.com?subject=Unsubscribe>
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .
_____
[Non-text portions of this message have been removed]