Solved

Need to create an enum type for three different environments.

Posted on 2008-06-25
4
190 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

685 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