Hi .pd,
I tried NameObjectCollectionBase and it works fine for me. I wrote only one
Add method with the parameter of the base class and it returns correct class
names of the entries as expected.
However, unlike Hashtable and DictionaryBase
System.Collections.Specialized.NameObjectCollectio nBase allows you to have
more then one entry in the collection with the same name (key). In this case
BaseGet method returns always the first one. So my guess is that due to some
error in your code you add all objects under the same name (key) and/or read
the same key regardless what you pass as a object name to your get method.
In those cases if first elemet added in the collection is of type BaseType
it will return the same object over and over again. So check how you
generate the names for the objects.
Anyway, I'm little confused that adding overloads for the Add method solves
your problem. So my next guess is that you make some kind of cloning the
objects before adding them to the collection.
For example.
class Base: ICloneable
{
public object Clone()
{
return new Base(); //Clone the object
}
}
class Deriv1:Base, ICloneable
{
public object Clone()
{
return new Deriv1(); //Clone the object
}
}
and then you have
public void Add(string name, Base obj)
{
base.BaseAdd(name, obj.Clone());
}
This will lead to the results you had. The type of the objects in the
collection will always be Base.
Ofcourse the compiler thorws warning message and underlines Deriv1.Cone
method. But there are some situations where you can miss those hints.
The fact that you had those problems means that there is something wrong in
your code.
HTH
B\rgds
100
".pd." <sp*****@your.peril> wrote in message
news:Xn*****************************@194.83.179.10 2...
100 wrote on Wed 17 Dec 2003 05:58:56p:
Hi .pd,
GetType returns the real type of the object not the type of the
variable used to reference the object. In other words it has to work
for you. Are you sure your BaseGet(...) method works correctly?
So you're telling me I have write my own GetType()? I was afraid of that.
BaseGet() is a method belonging to the
System.Collections.Specialized.NameObjectCollectio nBase class. It ain't
mine.
.pd.