Skip to content

Instantly share code, notes, and snippets.

@fontanka16
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fontanka16/17624143daf12dbff602 to your computer and use it in GitHub Desktop.
Save fontanka16/17624143daf12dbff602 to your computer and use it in GitHub Desktop.
Type Safe Enum example
using System;
using System.Collections.Generic;
namespace Viola.CallSlipFetching
{
public sealed class CallSlipDeliveryTypes
{
private readonly string _name;
private static readonly Dictionary<string, CallSlipDeliveryTypes> Instance = new Dictionary<string, CallSlipDeliveryTypes>();
private CallSlipDeliveryTypes(string name)
{
_name = name;
Instance[name] = this;
}
public static explicit operator CallSlipDeliveryTypes(string str)
{
CallSlipDeliveryTypes result;
if (Instance.TryGetValue(str, out result))
return result;
else
throw new InvalidCastException();
}
/// <summary>
/// FJärrut
/// </summary>
public static readonly CallSlipDeliveryTypes ILLOUT = new CallSlipDeliveryTypes("Fjärrut fysiskt material");
/// <summary>
/// Kopia
/// </summary>
public static readonly CallSlipDeliveryTypes COPY = new CallSlipDeliveryTypes("Fjärrut kopia");
/// <summary>
/// Magasinsbeställning
/// </summary>
public static readonly CallSlipDeliveryTypes STACKCALL = new CallSlipDeliveryTypes("Magasin");
/// <summary>
/// Direktleverans
/// </summary>
public static readonly CallSlipDeliveryTypes DIRECTDELIVERY = new CallSlipDeliveryTypes("Direktleverans");
/// <summary>
/// Sakanade
/// </summary>
public static readonly CallSlipDeliveryTypes MISSING = new CallSlipDeliveryTypes("Saknade");
///<summary>
/// Saknade
/// </summary>
public static readonly CallSlipDeliveryTypes MISSINGSEARCHEDONCE = new CallSlipDeliveryTypes("MissingSearchedOnce");
public override String ToString()
{
return _name;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment