Dynamic return with switch case

Viewed 37

I have a method that return a value based on a switch case, I am looking for a way to refactor it and make it dynamic, any tips please. Here is my method:

public dynamic Test(int levelTypeId, object value)
    {
        switch (levelTypeId)
        {
            case Constants.Db.DTT.IdInteger:
            case Constants.Db.DTT.IdMoney:
                return Convert.ToInt32(value);
                break;
            case Constants.Db.DTT.IdLookup:
            case Constants.Db.DTT.IdSequentialLookup:
                // M_DTT_ID_INTEGER, M_DTT_ID_MONEY
                var vResult = Convert.ToInt32(value);
                if ((vResult < 0))
                {
                    throw new Exception("Invalid lookup value.");
                }

                return vResult;
                break;
            //break;
            case Constants.Db.DTT.IdBoolean:
                var sValue = value.ToString();
                // if
                // M_DTT_ID_LOOKUP, M_DTT_ID_SEQUENTIAL_LOOKUP
                vResult = Convert.ToInt32(sValue);
                if (((vResult > 1) || (vResult < 0)))
                {
                    throw new Exception("Invalid boolean value.");
                }

                return vResult;
                break;
            // M_DTT_ID_BOOLEAN
        }
        //return test;
    }
0 Answers
Related