"mopicus" <mo*****@discussions.microsoft.com> a écrit dans le message de
news:
3E**********************************@microsoft.com...
| public class BaseObject
| {
| public BaseObjectCollection<BaseObject> CollectionRef;
| }
|
| public class BaseObjectCollection<T> : BindingList<T>
| {
| }
|
| public class EmployeeCollection : BaseObjectCollection<Employee>
| {
| }
|
|
| public class Employee : BaseObject
| {
|
| public Employee()
| {
| EmployeeCollection emp = this.CollectionRef as EmployeeCollection;
| // compile ERROR : invalid cast
| }
|
| }
|
|
| i think this example best illustrates what i want
| thankyou anyways
Sorry, but you are still over-engineering here and you are going to get
bitten by the covariance problems when you try to convert a
BindingList<BaseObject> to BindingList<Employee>; this simply won't work.
See many previous posts on covariance.
You don't need to subclass these generic classes, simply use them as they
are.
public class BaseObject
{
}
public class Employee : BaseObject
{
}
public class Company : BaseObject
{
private BindingList<Employee> employees = new BindingList<Employee>();
...
}
And I don't see why you would want to include a list of Employees in the
Employee class; this would mean that every single employee would also have a
list of *all* employees inside them ???
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer