如何通过key获取value值,键找值!多线程单利模式
模拟微软风格的写法,语义极其清晰,上代码
public partial class ProsessApprove : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ProcessDesignStatusEnum status = new ProcessDesignStatusEnum();
string key = status.未提交.key;
string value = status.未提交.value;
string value01 = status.ConvertKeyToValue.SetKey(1);//通过key获取值
}
}
上面的这是使用
如何定义直接看下面的代码
namespace CPACN_Collaboration.uImproving.ProcessDesign
{
public abstract class BaseStatus
{
public string[,] arr = new string[5, 2];
public BaseStatus()
{
arr[0, 0] = "未提交";
arr[0, 1] = "1";
arr[1, 0] = "待确认";
arr[1, 1] = "2";
arr[2, 0] = "已确认";
arr[2, 1] = "3";
arr[3, 0] = "待部署";
arr[3, 1] = "4";
arr[4, 0] = "待部署";
arr[4, 1] = "5";
}
public string SetKey(int key)
{
if (key >= 5 || key <= 1)
{
return "错误的状态";
}
return arr[key - 1, 0];
}
}
public class MethodClass
{
public class 未提交 : BaseStatus
{
private static 未提交 instance;
private static object _lock = new object();
private 未提交()
{
}
public static 未提交 GetInstance()
{
if (instance == null)
{
lock (_lock)
{
if (instance == null)
{
instance = new 未提交();
}
}
}
return instance;
}
public string value
{
get { return base.arr[0, 0]; }
}
public string key
{
get { return base.arr[0, 1]; }
}
}
public class 待确认 : BaseStatus
{
private static 待确认 instance;
private static object _lock = new object();
private 待确认()
{
}
public static 待确认 GetInstance()
{
if (instance == null)
{
lock (_lock)
{
if (instance == null)
{
instance = new 待确认();
}
}
}
return instance;
}
public string value
{
get { return base.arr[1, 0]; }
}
public string key
{
get { return base.arr[1, 1]; }
}
}
public class 已确认 : BaseStatus
{
private static 已确认 instance;
private static object _lock = new object();
private 已确认()
{
}
public static 已确认 GetInstance()
{
if (instance == null)
{
lock (_lock)
{
if (instance == null)
{
instance = new 已确认();
}
}
}
return instance;
}
public string value
{
get { return base.arr[2, 0]; }
}
public string key
{
get { return base.arr[2, 1]; }
}
}
public class 待部署 : BaseStatus
{
private static 待部署 instance;
private static object _lock = new object();
private 待部署()
{
}
public static 待部署 GetInstance()
{
if (instance == null)
{
lock (_lock)
{
if (instance == null)
{
instance = new 待部署();
}
}
}
return instance;
}
public string value
{
get { return base.arr[3, 0]; }
}
public string key
{
get { return base.arr[3, 1]; }
}
}
public class 已部署 : BaseStatus
{
private static 已部署 instance;
private static object _lock = new object();
private 已部署()
{
}
public static 已部署 GetInstance()
{
if (instance == null)
{
lock (_lock)
{
if (instance == null)
{
instance = new 已部署();
}
}
}
return instance;
}
public string value
{
get { return base.arr[4, 0]; }
}
public string key
{
get { return base.arr[4, 1]; }
}
}
public class ConvertKeyToValue : BaseStatus
{
/// <summary>
/// 获得Value
/// </summary>
/// <param name="key">状态数字</param>
/// <returns></returns>
public string value(int key)
{
return base.GetValueByKey(key);
}
}
}
public class ProcessDesignStatusEnum
{
public MethodClass.未提交 未提交
{
get { return MethodClass.未提交.GetInstance(); }
}
public MethodClass.待确认 待确认
{
get { return MethodClass.待确认.GetInstance(); }
}
public MethodClass.已确认 已确认
{
get { return MethodClass.已确认.GetInstance(); }
}
public MethodClass.待部署 待部署
{
get { return MethodClass.待部署.GetInstance(); }
}
public MethodClass.已部署 已部署
{
get { return MethodClass.已部署.GetInstance(); }
}
public MethodClass.ConvertKeyToValue ConvertKeyToValue
{
get { return new MethodClass.ConvertKeyToValue(); }
}
}
}