Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to create an enum type for three different environments.

Posted on 2008-06-25
4
Medium Priority
?
203 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

971 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