Merge pull request #8 from LongNEO/master

实例处理
This commit is contained in:
Kevin
2019-04-26 08:50:49 +08:00
committed by GitHub
2 changed files with 32 additions and 5 deletions
+13 -3
View File
@@ -23,7 +23,7 @@ namespace OSS.Common.ComModels.Enums
/// 成功
/// </summary>
[OSDescript("正常")] None = 0,
/// <summary>
/// 无法连接
/// </summary>
@@ -33,16 +33,26 @@ namespace OSS.Common.ComModels.Enums
/// 超时
/// </summary>
[OSDescript("超时")] TimeOut = 200,
/// <summary>
/// 任务失败
/// </summary>
[OSDescript("任务失败")] TaskFailed = 300,
/// <summary>
/// 等待重试
/// </summary>
[OSDescript("等待重试")] WaitRetry = 400,
/// <summary>
/// 内部错误(服务器错误)
/// </summary>
[OSDescript("内部错误")] InnerError = 500,
[OSDescript("系统错误")] InnerError = 500,
/// <summary>
/// 等待重试
/// </summary>
[OSDescript("等待响应")] WaitingResponse = 600,
}
/// <summary>
+19 -2
View File
@@ -17,11 +17,28 @@ namespace OSS.Common.ComUtils
get
{
if (instanceCreater == null)
throw new Exception(string.Concat( " 并没有设置", typeof(T).Name, "对应的映射类型! "));
throw new Exception(string.Concat(" 并没有设置", typeof(T).Name, "对应的映射类型! "));
return instanceCreater();
}
}
/// <summary>
/// 获取类型实例
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public static bool TryGet(out T t)
{
if (instanceCreater == null)
{
t = default(T);
return false;
}
t = instanceCreater();
return true;
}
private static Func<T> instanceCreater;
private static T instance;
@@ -37,7 +54,7 @@ namespace OSS.Common.ComUtils
if (instanceCreater == null)
instanceCreater = () =>
{
if(isSingle) return new TInstance();
if (isSingle) return new TInstance();
if (instance != null) return instance;
return instance = new TInstance();