global constants

N

.NET beginner

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.
 
P

Peter Rilling

Well, you could use embedded resources, or you could just make the constants
static in some class that your operations can use.
 
G

Guest

Thanks Peter for your reply. what did you mean by embedded
resources? Thanks a lot for your input.
 
P

Peter Rilling

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.
 
J

john conwell

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 **********";
}
}
 
G

Guest

thanks a lot Jon. That helped a lot.
-----Original Message-----
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 **********";
}
}



.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top