By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,608 Members | 3,801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,608 IT Pros & Developers. It's quick & easy.

Problem with generics replacing hashtable

P: n/a
WT
Hello,

I was using hastable to store collection of objects of the same class
MyClass.
I start replacing this hastable by a Dictionary<string,MyClass>....but
I was storing this hastable in cache an accessing it from another component
in an Provider.
This component was developped in a separate assembly and loaded dynamically.
There was no need for it to know Myclass, it was simply retrieving a
hastable and using the ToString() method on each value.

Now that I store Dictionary<string,MyClass> in cache , I don't know how to
implement this module,
Adding MyClass to it project is not easy due to interrelated classes, I
would have to add lot of classes, and may be place them in a separate
assembly which I don't want.
Is there some way to tell it that what it takes from cache could be casted
to Dictionary<string,object> rather than Dictionary<string,MyClass> ????
or to some general interface used by Dictionary<K,T> that could allow me to
call ToString() on the values ????

This seems to be a general problem, should I go back to my hashtable
implementation ?

Thanks to generic gurus for help.

CS
Apr 6 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
CS,

The only way you can do this is if you declare your Dictionary initially
as Dictionary<string, object>. Another option would be to define an
interface for MyClass which has the same methods exposed by MyClass, and
then have your dictionary declared as Dictionary<string, IMyClass>. You can
then define the interface in an assembly that is referenced by both the
calling code, and the assembly that is loaded dyamically.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"WT" <WT@newsgroups.nospam> wrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
Hello,

I was using hastable to store collection of objects of the same class
MyClass.
I start replacing this hastable by a Dictionary<string,MyClass>....but
I was storing this hastable in cache an accessing it from another
component in an Provider.
This component was developped in a separate assembly and loaded
dynamically.
There was no need for it to know Myclass, it was simply retrieving a
hastable and using the ToString() method on each value.

Now that I store Dictionary<string,MyClass> in cache , I don't know how to
implement this module,
Adding MyClass to it project is not easy due to interrelated classes, I
would have to add lot of classes, and may be place them in a separate
assembly which I don't want.
Is there some way to tell it that what it takes from cache could be
casted to Dictionary<string,object> rather than Dictionary<string,MyClass>
????
or to some general interface used by Dictionary<K,T> that could allow me
to call ToString() on the values ????

This seems to be a general problem, should I go back to my hashtable
implementation ?

Thanks to generic gurus for help.

CS

Apr 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.