Global Properties (i.e. application properties) in C# 
Author Message
 Global Properties (i.e. application properties) in C#

Ok, I'm coming over from VB6 and I know that OOP restricts this kind of
thing, but is there any way to load a global type that I can get at stuff
globally without having to load it all in maually every time? I cna't even
figure out how to store the currently logged in user so that all my forms
can see it properly.

Excuse the ignorance, but how would I go about doing something (not
everything, I like OOP but this is key!) like a module in Visual Basic 6?

Thanks!

James Hancock



Sun, 08 Aug 2004 07:31:15 GMT  
 Global Properties (i.e. application properties) in C#

James,

Quote:
> Ok, I'm coming over from VB6 and I know that OOP restricts this kind of
> thing, but is there any way to load a global type that I can get at stuff
> globally without having to load it all in maually every time? I cna't even
> figure out how to store the currently logged in user so that all my forms
> can see it properly.

> Excuse the ignorance, but how would I go about doing something (not
> everything, I like OOP but this is key!) like a module in Visual Basic 6?

You can use static members (in your case possibly a static field combined
with static property accessors should do nicely). For more complex cases,
using a singleton might just be a better option.

--
Tomas Restrepo



Sun, 08 Aug 2004 08:39:15 GMT  
 Global Properties (i.e. application properties) in C#
You can mark things in a class "static" (VB Shared). This makes them a
global instead of a member of a particular object instance.

See System.Math for an example...

--
Jonathan Allen


Quote:
> Ok, I'm coming over from VB6 and I know that OOP restricts this kind of
> thing, but is there any way to load a global type that I can get at stuff
> globally without having to load it all in maually every time? I cna't even
> figure out how to store the currently logged in user so that all my forms
> can see it properly.

> Excuse the ignorance, but how would I go about doing something (not
> everything, I like OOP but this is key!) like a module in Visual Basic 6?

> Thanks!

> James Hancock



Sun, 08 Aug 2004 07:48:53 GMT  
 Global Properties (i.e. application properties) in C#
For what it's worth, I'm another VBer coming over to the True Religion of
OOP. The high priests do frown upon global variables-- instead they
encourage us to ask "What is the nature of a User?" What are its attributes?
What responsibilities does it have?"

All kidding aside, I have found the transition to be worthwhile. One of the
first things it forced me to do was to kill globals in favor of objects like
User. That was the first step for me toward creating programs made up of
collaborating objects, rather than intelligent data structures that are
driven by "the program."

I'm going through a good book that is addressing a lot of the VS.Net and OOP
questions I have-- "OOP With Microsoft Visual Basic and Microsoft Visual C#
.Net", by Robin Reynolds-Haertle. I recommend it to anyone making the
transition from VB6 to VS.Net.

--
Dave Veeneman
Chicago, USA



Sun, 08 Aug 2004 10:13:54 GMT  
 Global Properties (i.e. application properties) in C#
OK, but it doesn't really answer my question? How do I make a class of users
that's available to all other forms etc. during the lifetime of the
application?  There's still tons of stuff that you need to store this way,
otherwise how the heck are you supposed to know who is logged on etc. if its
destroyed because it went out of scope?

Right now I'm forced to store this stuff in the registry... not nice.

James Hancock


Quote:
> Ok, I'm coming over from VB6 and I know that OOP restricts this kind of
> thing, but is there any way to load a global type that I can get at stuff
> globally without having to load it all in maually every time? I cna't even
> figure out how to store the currently logged in user so that all my forms
> can see it properly.

> Excuse the ignorance, but how would I go about doing something (not
> everything, I like OOP but this is key!) like a module in Visual Basic 6?

> Thanks!

> James Hancock



Mon, 09 Aug 2004 02:04:48 GMT  
 Global Properties (i.e. application properties) in C#
James,
Read about the Singleton Pattern in the following book:
http://labsoftware.com/labsoftware/CSharpPats/design_patterns_in_c.htm

Hope this helps
Jay


Quote:
> OK, but it doesn't really answer my question? How do I make a class of
users
> that's available to all other forms etc. during the lifetime of the
> application?  There's still tons of stuff that you need to store this way,
> otherwise how the heck are you supposed to know who is logged on etc. if
its
> destroyed because it went out of scope?

> Right now I'm forced to store this stuff in the registry... not nice.

> James Hancock



> > Ok, I'm coming over from VB6 and I know that OOP restricts this kind of
> > thing, but is there any way to load a global type that I can get at
stuff
> > globally without having to load it all in maually every time? I cna't
even
> > figure out how to store the currently logged in user so that all my
forms
> > can see it properly.

> > Excuse the ignorance, but how would I go about doing something (not
> > everything, I like OOP but this is key!) like a module in Visual Basic
6?

> > Thanks!

> > James Hancock



Mon, 09 Aug 2004 11:05:24 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Properties with properties, properties of value type

2. Properties as global variables

3. Global properties set in Server accessible by Clients

4. Is there a special property at global variable?

5. Setting a property of a property

6. ActiveX property changes and Visual Basic Property Browser

7. Accesing put_ property without get_ property in VB

8. Associating multiple properties with the same property page

9. Property Sheet and Property pages in ATL

10. Property page and VB properties view synchronization

11. How to disable property page on property sheet.

12. Property Sheet within a Property Sheet

 

 
Powered by phpBB® Forum Software