470,641 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

Problem with generics replacing hashtable

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
1 1482
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.

Similar topics

1 post views Thread by Keith R | last post: by
13 posts views Thread by Anders Borum | last post: by
5 posts views Thread by J.Marsch | last post: by
8 posts views Thread by Chris Dunaway | last post: by
2 posts views Thread by Daniel Billingsley | last post: by
9 posts views Thread by sloan | last post: by
3 posts views Thread by Showjumper | last post: by
10 posts views Thread by Frank Rizzo | last post: by
1 post views Thread by =?Utf-8?B?TWFyaw==?= | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.