I have the following class:
public class Content {
public int Key { get; set; }
public int Order { get; set; }
public string Title { get; set; }
}
I have the following function that returns a content type code depending on an id.
protected string getType(string id) {
switch(id.Substring(2, 2)) {
case "00": return ("14");
case "1F": return ("11");
case "04": return ("10");
case "05": return ("09");
default: return ("99");
}
}
Although the id is not part of the content class the class and function are always used together.
Is there some way I could cleanly fit this function into my class? I was thinking of an enum or something fixed however my knowledge of C# isn't really good enough for me to know how I could do this. I hope someone can give me and example.
Update:
I like the following suggestion:
public static readonly Dictionary<String, String> IdToType =
new Dictionary<string, string>
{
{"00", "14"},
{"1F", "11"},
{"04", "10"},
{"05", "09"},
//etc.
};
but I don't know how I could fit this into my class. Is there anyone out there who could show me? What I would like to be able to do is write something like this:
Content.getType("00")
With data stored in the dictionary as suggested.