.NET Custom Type Enum
Custom Type Enum (Exemplo: Application)
internal static class Application
{
public static FileFormat Pdf { get { return new FileFormat("pdf", "application/pdf"); } }
public static FileFormat Excel { get { return new FileFormat("xlsx", "application/vnd.ms-excel"); } }
}
internal sealed class FileFormat
{
private readonly string _extension;
private readonly string _mediaType;
public FileFormat(string extension, string mediaType)
{
this._extension = extension;
this._mediaType = mediaType;
}
public string Extension { get { return _extension; } }
public string MediaType { get { return _mediaType; } }
}
Invocação
static void MyMethod (FileFormat fileFormat)
{
Console.WriteLine(fileFormat.Extension + " " + fileFormat.MediaType);
}
MyMethod(Application.Excel)
Licença CC BY-SA 4.0
Silvia Pinhão Lopes, 23.6.17
Sem comentários: