473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

file of constants? (vs2005/c#)

Good day, bare with me while I probably ask a very novice question...

I have multiple projects that use the same constants. I want to create
a common file they can share.

Is this the best way to do it:

using System;

namespace myconsts
{
class orderconsts
{
public const int ORDER_STATUS_HOLD = 1;
public const int ORDER_STATUS_ERROR = 2;
public const int ORDER_STATUS_READYTOSHIP = 3;
public const int ORDER_STATUS_PACKAGED = 4;
public const int ORDER_STATUS_SHIPPED = 5;
public const int ORDER_STATUS_VOIDED = 6;
}
}

and access it using orderconsts.ORDER_STATUS_HOLD

-Markus_R

Aug 22 '06 #1
4 1850
First, I'd think this would be an enum. Second, you'd probably want to
embed this in your Order class, which knows about its own status.
Other projects which need to know order status would likely ask this
order class.

HTH
Andy

MarkusR wrote:
Good day, bare with me while I probably ask a very novice question...

I have multiple projects that use the same constants. I want to create
a common file they can share.

Is this the best way to do it:

using System;

namespace myconsts
{
class orderconsts
{
public const int ORDER_STATUS_HOLD = 1;
public const int ORDER_STATUS_ERROR = 2;
public const int ORDER_STATUS_READYTOSHIP = 3;
public const int ORDER_STATUS_PACKAGED = 4;
public const int ORDER_STATUS_SHIPPED = 5;
public const int ORDER_STATUS_VOIDED = 6;
}
}

and access it using orderconsts.ORDER_STATUS_HOLD

-Markus_R
Aug 22 '06 #2
Hey Andy,

Actually you are probably right. I forget to use enums. (consts always
start out with 1 or 2 and grow).

This project that I am doing is extremely small and I opted to not use
OO for everything. About 80 lines of code. But, again, another good
point. I will have to think if I could organize all into a reusable
class.

-Markus_R

Andy wrote:
First, I'd think this would be an enum. Second, you'd probably want to
embed this in your Order class, which knows about its own status.
Other projects which need to know order status would likely ask this
order class.

HTH
Andy

MarkusR wrote:
Good day, bare with me while I probably ask a very novice question...

I have multiple projects that use the same constants. I want to create
a common file they can share.

Is this the best way to do it:

using System;

namespace myconsts
{
class orderconsts
{
public const int ORDER_STATUS_HOLD = 1;
public const int ORDER_STATUS_ERROR = 2;
public const int ORDER_STATUS_READYTOSHIP = 3;
public const int ORDER_STATUS_PACKAGED = 4;
public const int ORDER_STATUS_SHIPPED = 5;
public const int ORDER_STATUS_VOIDED = 6;
}
}

and access it using orderconsts.ORDER_STATUS_HOLD

-Markus_R
Aug 22 '06 #3

I do mine like this:

public enum ExampleEnum
{
[Description("MyUnknownDescription")] Unknown = 0
[Description("Items of this enum are the coolest")] SuperCool =
1
}

Ok.. then I have a EnumHelper.
using System;
using System.ComponentModel;
using System.Reflection;
using System.Xml;

namespace MyCompany.Enums
{
/// <summary>
/// Summary description for EnumHelper.
/// </summary>
public class EnumHelper
{
private EnumHelper()
{
//only static methods
}

public static string GetDescription(System.Enum value)
{

//if a description is defined for an enum value, this procedure will get
it

//Example of defining a description with an enum value
/*
*

public enum ExampleEnum
{
[Description("MyUnknownDescription")] Unknown = 0
}
*
* */

FieldInfo fi= value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribut e),
false);
return (attributes.Length>0)?attributes[0].Description:value.ToString();

}

}
I kinda get the best of both worlds.
I use the enums as enums 99% of the time.

But I have get a long description if I ever need it.


"MarkusR" <ma*******@gmail.comwrote in message
news:11********************@h48g2000cwc.googlegrou ps.com...
Good day, bare with me while I probably ask a very novice question...

I have multiple projects that use the same constants. I want to create
a common file they can share.

Is this the best way to do it:

using System;

namespace myconsts
{
class orderconsts
{
public const int ORDER_STATUS_HOLD = 1;
public const int ORDER_STATUS_ERROR = 2;
public const int ORDER_STATUS_READYTOSHIP = 3;
public const int ORDER_STATUS_PACKAGED = 4;
public const int ORDER_STATUS_SHIPPED = 5;
public const int ORDER_STATUS_VOIDED = 6;
}
}

and access it using orderconsts.ORDER_STATUS_HOLD

-Markus_R

Aug 22 '06 #4
Thanks much sloan. I will have to study this. ;)

-Markus

sloan wrote:
I do mine like this:

public enum ExampleEnum
{
[Description("MyUnknownDescription")] Unknown = 0
[Description("Items of this enum are the coolest")] SuperCool =
1
}

Ok.. then I have a EnumHelper.
using System;
using System.ComponentModel;
using System.Reflection;
using System.Xml;

namespace MyCompany.Enums
{
/// <summary>
/// Summary description for EnumHelper.
/// </summary>
public class EnumHelper
{
private EnumHelper()
{
//only static methods
}

public static string GetDescription(System.Enum value)
{

//if a description is defined for an enum value, this procedure will get
it

//Example of defining a description with an enum value
/*
*

public enum ExampleEnum
{
[Description("MyUnknownDescription")] Unknown = 0
}
*
* */

FieldInfo fi= value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribut e),
false);
return (attributes.Length>0)?attributes[0].Description:value.ToString();

}

}
I kinda get the best of both worlds.
I use the enums as enums 99% of the time.

But I have get a long description if I ever need it.


"MarkusR" <ma*******@gmail.comwrote in message
news:11********************@h48g2000cwc.googlegrou ps.com...
Good day, bare with me while I probably ask a very novice question...

I have multiple projects that use the same constants. I want to create
a common file they can share.

Is this the best way to do it:

using System;

namespace myconsts
{
class orderconsts
{
public const int ORDER_STATUS_HOLD = 1;
public const int ORDER_STATUS_ERROR = 2;
public const int ORDER_STATUS_READYTOSHIP = 3;
public const int ORDER_STATUS_PACKAGED = 4;
public const int ORDER_STATUS_SHIPPED = 5;
public const int ORDER_STATUS_VOIDED = 6;
}
}

and access it using orderconsts.ORDER_STATUS_HOLD

-Markus_R
Aug 31 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bryan Harrington | last post by:
I'm working on an application that I will make use of "constants". I put contants in quotes becuase they will change periodically (Logo path, css path, psw expiration times etc). From a system...
34
by: E. Robert Tisdale | last post by:
Please find attached the physical constants header file physical.h It defines conversion factors to mks units. It might be used like this: > cat main.cc #include<iostream>...
9
by: john smith | last post by:
Hi, If I have a large constants file and include that in a .cpp file will the executable become large? That is if I include a file with a bunch of constants does the executable include all of...
5
by: HNguyen | last post by:
Hi all, I don't know how to include the files from an .aspx file using Visual Studio.NET. For example, I have a file containing the constants and I want to use these constants from aspx file....
3
by: tigrrgrr42 | last post by:
I am working(vb.net03and05) with word documents stored in a sql db and I am currently bringing them from a byte array into a temp file to pop into word and make word do its thing as a com object. ...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
by: Dv | last post by:
I have a API lib (written in C/C++) that can be used by C/C++ project. Now, I'm adding support to C# project. I changed the Lib to DLL. This is easy. However, I have no idea how to deal with the...
10
by: michael | last post by:
Hi All, I have the following: ------------ file constants.h--------- #ifndef constants_ #define constants_ const int FOO = 1; const int BAR = 2;
4
by: Uriel88 | last post by:
Hello, I am working with developing an application that uses the Netmon 3.2 API. Currently they have a PInvoke wrapper to access unmanaged C++ DLL functions. Basically what I am attempting to do...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.