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

global constants

P: n/a
Hi all
I need to create some strings, constants etc. in my class
library that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Well, you could use embedded resources, or you could just make the constants
static in some class that your operations can use.

".NET beginner" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Hi all
I need to create some strings, constants etc. in my class
library that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.

Nov 15 '05 #2

P: n/a
Thanks Peter for your reply. what did you mean by embedded
resources? Thanks a lot for your input.
-----Original Message-----
Well, you could use embedded resources, or you could just make the constantsstatic in some class that your operations can use.

".NET beginner" <an*******@discussions.microsoft.com> wrote in messagenews:01****************************@phx.gbl...
Hi all
I need to create some strings, constants etc. in my class library that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.

.

Nov 15 '05 #3

P: n/a
Are you familiar with the concept of resources? Basically, resources can be
embedded/compiled in your application so that are actually part of the
binaries (no satellite files). This is what those .resx files are. They
get embedded in your application when the code is compiled. You can create
your own .resx files and then use classes in the ResourceManager to access
them. Honestly I have not had much experience with resources. If you do
not need culture specific constants, you might just add them as static
constants in some utility class.
<an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Thanks Peter for your reply. what did you mean by embedded
resources? Thanks a lot for your input.
-----Original Message-----
Well, you could use embedded resources, or you could just

make the constants
static in some class that your operations can use.

".NET beginner" <an*******@discussions.microsoft.com>

wrote in message
news:01****************************@phx.gbl...
Hi all
I need to create some strings, constants etc. in my class library that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.

.

Nov 15 '05 #4

P: n/a
If you dont have any need for internationalization of your
strings i like using a nested structure of string
constants. Something like the following. Its hard to
read in the post, but just copy / paste it into your code
or notepad to see what i mean.
internal struct Constants
{
internal struct Errors
{
internal const string ErrMsgAddInName
= "CS Dev Tools";
internal const string ErrLoadingAddIn
= "Error loading Add-In: \r\n";
internal const string ErrInCodeFragMgr
= "Error in the code fragmant manager: \r\n";
internal const string ErrInsertCodeFrag
= "Error inserting code fragment into code window: \r\n";
internal const string ErrNoTextSelected
= "No text was selected in code window";
internal const string
ErrCodeFragNameExists = "Code Fragment already has this
name.\r\nPlease choose another name";
}

internal struct UndoContexts
{
internal const string ADD_FRAGMENT
= "AddFragment";
internal const string ADD_CODEREVIEW_ITEM
= "AddCodeReviewItem";
internal const string NEW_PROPERTY
= "NewProperty";
internal const string NEW_MSGBOX
= "NewMsgBox";
internal const string ADD_REGION
= "AddRegion";
internal const string ADD_REGEX
= "AddRegEx";
internal const string ADD_CONSTRING
= "AddConnectionString";
}

internal struct Kinds
{
internal const string vsViewKindCode
= "{7651A701-06E5-11D1-8EBD-00A0C90F26EA}";
internal const string vsCMLanguageVB
= "{B5E9BD33-6D3E-4B5D-925E-8A43B79820B4}";
}

internal struct OutputMsg
{
internal const string Output_Spaces = " ";
internal const string Clean_Name = "-------
--- Cleaning Solution ----------";
internal const string Clean_SavingSolution
= " 1. Saving solution all projects";
internal const string Clean_CloseSolution
= " 2. Closing solution";
internal const string Clean_DeleteFiles
= " 3. Deleting intermediate files and output files
for projects:";
internal const string Clean_ReOpenSolution
= " 4. Re-opening solution";
internal const string Clean_Building
= " 5. Building solution";
internal const string Clean_Finished
= "********** Clean finished **********";
}
}
-----Original Message-----
Hi all
I need to create some strings, constants etc. in my class
library that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.
.

Nov 15 '05 #5

P: n/a
thanks a lot Jon. That helped a lot.
-----Original Message-----
If you dont have any need for internationalization of yourstrings i like using a nested structure of string
constants. Something like the following. Its hard to
read in the post, but just copy / paste it into your code
or notepad to see what i mean.
internal struct Constants
{
internal struct Errors
{
internal const string ErrMsgAddInName
= "CS Dev Tools";
internal const string ErrLoadingAddIn
= "Error loading Add-In: \r\n";
internal const string ErrInCodeFragMgr
= "Error in the code fragmant manager: \r\n";
internal const string ErrInsertCodeFrag
= "Error inserting code fragment into code window: \r\n";
internal const string ErrNoTextSelected
= "No text was selected in code window";
internal const string
ErrCodeFragNameExists = "Code Fragment already has this
name.\r\nPlease choose another name";
}

internal struct UndoContexts
{
internal const string ADD_FRAGMENT
= "AddFragment";
internal const string ADD_CODEREVIEW_ITEM
= "AddCodeReviewItem";
internal const string NEW_PROPERTY
= "NewProperty";
internal const string NEW_MSGBOX
= "NewMsgBox";
internal const string ADD_REGION
= "AddRegion";
internal const string ADD_REGEX
= "AddRegEx";
internal const string ADD_CONSTRING
= "AddConnectionString";
}

internal struct Kinds
{
internal const string vsViewKindCode
= "{7651A701-06E5-11D1-8EBD-00A0C90F26EA}";
internal const string vsCMLanguageVB
= "{B5E9BD33-6D3E-4B5D-925E-8A43B79820B4}";
}

internal struct OutputMsg
{
internal const string Output_Spaces = " ";
internal const string Clean_Name = "-------
--- Cleaning Solution ----------";
internal const string Clean_SavingSolution
= " 1. Saving solution all projects";
internal const string Clean_CloseSolution
= " 2. Closing solution";
internal const string Clean_DeleteFiles
= " 3. Deleting intermediate files and output filesfor projects:";
internal const string Clean_ReOpenSolution
= " 4. Re-opening solution";
internal const string Clean_Building
= " 5. Building solution";
internal const string Clean_Finished
= "********** Clean finished **********";
}
}
-----Original Message-----
Hi all
I need to create some strings, constants etc. in my classlibrary that need to be shared across all the classes in
my class library. How do I accomplish this?

Do these strings and constants have to be embedded in a
class? Is there a better way to do this?
Thanks for your help.
.

.

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.