I have an object with has two properties: Text
and Type
.
To avoid hard-coding the Types, I put them in the database, so they can be added to in future. At the moment the types are URL, Username and ID
.
However, I now want to run a Utility method to clean up the object's Text
field based on which Type
the object is (e.g. add 'http://' if its a URL).
Is there a way to do this in the Utilities class without hard-coding the types in a switch statement/if else block.
switch (type)
{
case 1:
TidyUrl();
case 2:
TidyUsername();
case 3:
TidyID();
default:
break;
}
In this example I'm hardcoding the IDs from the database ('Type' table), which can never be a good thing!
Is there a better way to do this?