Solved

Properties.Settings.Default, multiple values

Posted on 2010-11-11
7
456 Views
Last Modified: 2012-05-10
I'm working on an application an we need conditional statements for multiple locations.
There could be two or more locations.

Is there another way of coding for a certain location?
So far, I would just use a conditional statement.
if (Properties.Settings.Default.Location == "abc")
                {
                   //do stuff
                }

Open in new window

0
Comment
Question by:JRockFL
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Accepted Solution

by:
xDJR1875 earned 500 total points
ID: 34115568
well most obvious is using switch(){} but that may not save you much.

create the do stuff method()

switch (Properties.Setting.Default.Location)
{
     case "abc":
              dostuff("abc");
               break;
    case "bcd":
              dostuff("bcd")
              break;
}
0
 
LVL 8

Author Comment

by:JRockFL
ID: 34115609
Yeah I thought about that too, What about creating an enumerator?
Then when I instantiate the class,  I can set a property with the current location.

if (Location == Locations.Texas)
{
    //do stuff
}
0
 
LVL 17

Expert Comment

by:xDJR1875
ID: 34115797
an enumerator will still require you to check which it is somehow using if or switch.

The creation of a class with methods / branches that will process depending on the value of its location property would be a clean way to implement this, but you still need to check the value in the class, just not in the calling method.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:ajb2222
ID: 34116204
You could create a class that has specific methods and properties

then create a class for each location based on the first class you created and override any mothods or properties that are diferent for that location

Then when some processing just call the correct method.

Look into Object Oriented Programming.

0
 
LVL 8

Author Comment

by:JRockFL
ID: 34116299
ajb2222,

can you provide a code sample?
0
 
LVL 6

Expert Comment

by:ajb2222
ID: 34122123
what I am talking about is  inheritance and  polymorphism which are two major concepts in object oriented programming.  The link is an example that explains the concept and how to apply it.

http://www.codeproject.com/KB/cs/csharpintro01.aspx

0
 
LVL 8

Author Closing Comment

by:JRockFL
ID: 34248524
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linq Help 1 35
Using C#, how could you improve upon my method of writing out a merged, compressed file? 2 34
Entity Framework 7 31
Exit the loop 4 34
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

16 Experts available now in Live!

Get 1:1 Help Now