m_finn
m_finn

Reputation: 189

Using App.Config to derive which class/variables to use

I'm building a selenium framework which needs to behave differently between different customers e.g. 2 customers will have slightly different webpages

I'm trying to drive this from the app.config appsettings e.g.

<add key="Customer" value="ABC" /> 

I then have a Customer classes:

public static class Customer
    {
        public static string CustomerName = ConfigurationManager.AppSettings["Customer"];
        public static string custAddress = {CustomerName}.custAddress ; //this is obviously wrong - how do i do this?...
    }

public static class ABC
    {
        custAddress = "customer abc address";

    }

public static class DEF
    {
        custAddress = "customer def address";

    }

I want to then call it the simplest way possible to get the value e.g.

var address = Customer.custAddress;

...which will be set depending on the app.config setting.

I'm a c# newbie so apologies for the lack of clarity - i've been trying to figure out how to cast the customer string into the class of its namesake. I thought interfaces may also be an option but struggling with the complexity. Is there a better way?

Upvotes: 1

Views: 73

Answers (1)

tmaj
tmaj

Reputation: 35115

I suggest that you have a set of settings per customer and the address is simply AppSettings["Address"].

This way you don't need to modify your code when a 3rd customer is added. If you keep class ABC then there is not much point in having settings.

Upvotes: 1

Related Questions