Solved

Need to create an enum type for three different environments.

Posted on 2008-06-25
4
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

623 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