patterncsharpMinor
Email template referencer
Viewed 0 times
templatereferenceremail
Problem
Which is best practice for creating an enum-like lookup for templates? I enjoy being able to bring up my templates with VS IntelliSense so either works for me.
Option 1 (
Option 2 (
Option 1 (
enum/Dictionary combo):public enum Template
{
AccountInformation = 1,
Registration = 2,
Signed = 3
}
static readonly IDictionary TemplateData = new Dictionary()
{
{Template.AccountInformation, "accountinfo.txt"},
{Template.Registration, "registration.txt"},
{Template.Signed, "signed.txt"}
};Option 2 (
static class):public static class Template
{
public static String AccountInformation = "accountinfo.txt";
public static String Registration = "registration.txt";
public static String Signed = "signed.txt";
}Solution
Try this:
For more information: String Enumerations in C#
Otherwise, I prefer your second option.
public enum Template
{
[StringValue("accountinfo.txt")]
AccountInformation = 1,
[StringValue("registration.txt")]
Registration = 2,
[StringValue("signed.txt")]
Signed = 3
}For more information: String Enumerations in C#
Otherwise, I prefer your second option.
Code Snippets
public enum Template
{
[StringValue("accountinfo.txt")]
AccountInformation = 1,
[StringValue("registration.txt")]
Registration = 2,
[StringValue("signed.txt")]
Signed = 3
}Context
StackExchange Code Review Q#24669, answer score: 2
Revisions (0)
No revisions yet.