Solved

Need to create an enum type for three different environments.

Posted on 2008-06-25
4
184 Views
Last Modified: 2013-12-16
public enum Environment
    {
        test   = "System Integration Testing",
        accept = "Client Acceptance Testing",
        prod   = "Production",
    }
When the user comes back a string how should I assign a label the value of for example
test
It should say System Integration Testing.
0
Comment
Question by:mathieu_cupryk
  • 2
4 Comments
 
LVL 10

Expert Comment

by:oxyoo
Comment Utility
Hi,

There is a useful blog post on the subject here..
http://blogs.msdn.com/abhinaba/archive/2005/10/20/483000.aspx

Good Luck!
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
Comment Utility
not sure about your needs, but you cannot do as you described. A near approach could be using attributes:
public enum Environment
{
       [Description("System Integration Testing")]
        test,
       [Description("Client Acceptance Testing")]
        accept,
       [Description("Production")]
        prod
}

to get the description of an enum value, you can use a helper method:

public static string GetStringValue(Environment value)
{
        FieldInfo fi = value.GetType().GetField(value.ToString());
        object[] attrs = fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
        return ((DescriptionAttribute)attrs[0]).Description;
}


0
 

Author Comment

by:mathieu_cupryk
Comment Utility
how can i get the environment from the connection string.
if I have
SCWB2.WPG.CWB.CA
UCWB2.WPG.CWB.CA
first character.
S--> System Integration Testing.
U--> Client Acceptance Testing.

  <add name="InitialPriceReporting.Properties.Settings.ConnectionString" connectionString="Data Source=SCWB2.wpg.cwb.ca;Persist Security Info=True;User ID=init_price;Password=init_77day;Unicode=True" providerName="System.Data.OracleClient"/>
 
Need to get it from the name
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
Hi, you should post a new question for this, the solution is not simple, you have to make some pasing tasks.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now