Click here to Skip to main content
15,885,941 members
Articles / Programming Languages / C#

Refactoring a Switch Statement

Rate me:
Please Sign up or sign in to vote.
3.33/5 (7 votes)
15 Aug 2009CPOL 56.4K   317   14  
Avoiding a switch statement in order to avoid Cyclomatic complexity.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Refactoring_Switch
{
    class Program
    {
        static void Main(string[] args)
        {
            DeviceController deviceController = new DeviceController();
            Console.WriteLine(deviceController.GetDeviceState().ToString());
            deviceController.ChangeDeviceState(DeviceStatesEnum.Active);
            Console.WriteLine(deviceController.GetDeviceState().ToString());
            deviceController.ChangeDeviceState(DeviceStatesEnum.PowerUp);
            Console.WriteLine(deviceController.GetDeviceState().ToString());
            Console.Read();
        }


    }

    public enum DeviceStatesEnum
    {
        PowerUp,
        Waiting,
        StandBy,
        Inactive,
        Active,
        Start,
        Ready,
        Equilibrating,
        StartRunning,
        Running,
        ShoutingDown,
        ShoutDown,
        WarmingUp,
        Error
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) MphasiS an HP company
India India
I am dotnet programmer

Comments and Discussions