Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2007

Tip: Looking for answers? Try searching our database.

Add a Hashtable to Applicatoin to save Global data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ryan Liu - 30 Dec 2007 08:09 GMT
Is that a good idea to add a Hashtable to System.Windows.Forms.Application
class? And we can put any user global data in it.

I have some class library used by a few other applications in slight
different way. This way (and ocz there are other ways) I don't have to user
different parameter to call a method or invent an other global data
repository.

Regards,

~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

 Ryan Liu
 Shanghai Fengpu Software Co. Ltd
 Shanghai , China

 http://www.PowerCATI.com  Powerful CATI!
 http://www.fpsoft.net.cn
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
Peter Duniho - 30 Dec 2007 08:32 GMT
> Is that a good idea to add a Hashtable to  
> System.Windows.Forms.Application class? And we can put any user global  
[quoted text clipped - 4 lines]
> user different parameter to call a method or invent an other global data  
> repository.

What's wrong with just making a static class for your global data?  Or a  
static member of some more-relevant class?  (Stored in a Hashtable, or  
whatever other container you find appropriate, of course).

I mean, I suppose you could use extension to add something to the  
Application class, but I'm not sure what the point would be.  What's so  
tempting about the Application class that you want to put your data there  
rather than something more specific to your own code?

Pete
Peter Duniho - 30 Dec 2007 08:43 GMT
> [...]
> I mean, I suppose you could use extension to add something to the  
> Application class [...]

Actually, strike that.  I overlooked that you can only add an extension  
method as an instance method, and with no way to get an instance of the  
Application class, you can't extend it even via extension methods.

So you're out of luck anyway.  The Application class is sealed and there's  
no way for you to add new data members to it anyway, rendering the  
question moot.

Pete
Ryan Liu - 30 Dec 2007 10:07 GMT
>> [...]
>> I mean, I suppose you could use extension to add something to the
[quoted text clipped - 9 lines]
>
> Pete

Peter,

After the post, I find the System.Enviorment class is for this purpose. But
it's key and value is only string type. Now I do come out with my own static
class which use Hashtable internally.

Regards,
Ryan
Marc Gravell - 30 Dec 2007 10:54 GMT
> After the post, I find the System.Enviorment class is for this purpose.
I realise you aren't using this, but for completeness, I suspect that
this is intended for environment variables

> Now I do come out with my own static class which use Hashtable internally.
Nobody will stop you; but it doesn't seem very elegant; you will have
no assistance to help you know the expected keys or types for
settings. I'm not sure this is buying you much... personally I'd be
more inclined to have a usage-specific class with typed, named
properties (quite probably static).

A final thought; watch out for thread safety and object lifetime
(objects held globally won't be garbage collected, nor will anything
they can see [think "events"]).

Marc
christery@gmail.com - 30 Dec 2007 13:03 GMT
> > After the post, I find the System.Enviorment class is for this purpose.
>
> I realise you aren't using this, but for completeness, I suspect that
> this is intended for environment variables

as in what u see when u type "set" in a command prompt...

hmm...

this could get really complicated... a max len of env var at 255? no,
path can be longer now... but still... would not build hastables
there ;)

and yes, all strings, like WriteLine(Environment.CurrentDirectory);
will tell u where the os thinks u are...

//CY
christery@gmail.com - 30 Dec 2007 13:09 GMT
> and yes, all strings, like WriteLine(Environment.CurrentDirectory);

oh, forgot the point of that.. take 2 programs (same prog) start in
differrent dir and they will tell u different directorys.. I dont
think its shacer or common, initalized by system defaults but can be
set by process

//CY
Marc Gravell - 30 Dec 2007 13:39 GMT
Yes; my point being - I wouldn't go near this for internal application
data (which is what you are talking about).

Marc
Ryan Liu - 30 Dec 2007 15:59 GMT
----- Original Message -----
From: "Marc Gravell" <marc.gravell@gmail.com>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Sunday, December 30, 2007 6:54 PM
Subject: Re: Add a Hashtable to Applicatoin to save Global data

>> After the post, I find the System.Enviorment class is for this purpose.
> I realise you aren't using this, but for completeness, I suspect that
[quoted text clipped - 5 lines]
> no assistance to help you know the expected keys or types for
> settings.

Oh, I come out another enum for keys.

I'm not sure this is buying you much... personally I'd be
> more inclined to have a usage-specific class with typed, named
> properties (quite probably static).

I try to write a generic class to set/get applicaton level variables. (this
class itself does not bind to the enum I mentioned above). By doing this, I
think I can avoid writing more and more classes or adding more and more
properties. And worse when some properties get oboslated.

Ryan

> A final thought; watch out for thread safety and object lifetime
> (objects held globally won't be garbage collected, nor will anything
> they can see [think "events"]).
>
> Marc

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.