Solved

Need to create an enum type for three different environments.

Posted on 2008-06-25
4
189 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
ID: 21865370
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
ID: 21865760
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
ID: 21866832
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
ID: 21867425
Hi, you should post a new question for this, the solution is not simple, you have to make some pasing tasks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 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