2

Is there a better way to pass this through the addClick (ideally I don't want this at all and I would want it to auto-pass through)?

public void addClick(object sender, EventArgs e)
{
    if ((string) HttpContext.Current.Session["whichMenu"] == "systemDateFormats")
    {
        WorldViewNet.system.DateFormats dateformats = new WorldViewNet.system.DateFormats();
        dateformats.addClick();
    }
    else if ((string) HttpContext.Current.Session["whichMenu"] == "programmingLabels")
    {
        WorldViewNet.programming.Labels labels = new WorldViewNet.programming.Labels();
        labels.addClick();
    }
    else if ((string) HttpContext.Current.Session["whichMenu"] == "programmingPLUSearch")
    {
        WorldViewNet.programming.PLUSearch pluSearch = new WorldViewNet.programming.PLUSearch();
        pluSearch.addClick();
    }
    else if ((string) HttpContext.Current.Session["whichMenu"] == "programmingServings")
    {
        WorldViewNet.programming.Servings servings = new WorldViewNet.programming.Servings();
        servings.addClick();
    }
    else if ((string) HttpContext.Current.Session["whichMenu"] == "programmingShops")
    {
        WorldViewNet.programming.Shops shops = new WorldViewNet.programming.Shops();
        shops.addClick();
    }
    else if ((string) HttpContext.Current.Session["whichMenu"] == "programmingTextsSearch")
    {
        WorldViewNet.programming.TextsSearch textsSearch = new WorldViewNet.programming.TextsSearch();
        textsSearch.addClick();
    }
    else if ((string) HttpContext.Current.Session["whichMenu"] == "systemTemplates")
    {
        WorldViewNet.system.Templates templates = new WorldViewNet.system.Templates();
        templates.addClick();
    }
}

If anyone has any suggestions, that would help me out I would be grateful.

2
  • 2
    switch() {} perhaps Commented Nov 21, 2014 at 14:18
  • Or a dictionary of strings => actions. Commented Jul 31, 2015 at 16:59

1 Answer 1

1

I thing below models maybe good for your codes:

public void addClick(object sender, EventArgs e)
{
    object control;
    string opt = (string) HttpContext.Current.Session["whichMenu"];

    switch (opt)
    {
        case "systemDateFormats": control = new WorldViewNet.system.DateFormats();
            break;
        case "programmingLabels": control = new WorldViewNet.programming.Labels();
            break;
        case "programmingPLUSearch": control = new WorldViewNet.programming.PLUSearch();
            break;
        case "programmingServings": control = new WorldViewNet.programming.Servings();
            break;
        case "programmingShops": control = new WorldViewNet.programming.Shops();
            break;
        case "programmingTextsSearch": control = new WorldViewNet.programming.TextsSearch();
            break;
        case "systemTemplates": control = new WorldViewNet.system.Templates();
            break;
        default: new WorldViewNet.system.DefaultType();
    }

    ((dynamic)control).addClick();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.