Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
ff794fbebb
  1. 253
      SqlSugar/InstanceFactory.cs

253
SqlSugar/InstanceFactory.cs

@ -16,121 +16,121 @@ namespace SqlSugar
{
string className = "Queryable";
className = GetClassName(currentConnectionConfig.DbType, className);
ISugarQueryable<T> reval = CreateInstance<T, ISugarQueryable<T>>(className, currentConnectionConfig.DbType);
return reval;
ISugarQueryable<T> result = CreateInstance<T, ISugarQueryable<T>>(className);
return result;
}
public static ISugarQueryable<T, T2> GetQueryable<T, T2>(ConnectionConfig currentConnectionConfig)
{
string className = "Queryable";
className = GetClassName(currentConnectionConfig.DbType, className);
ISugarQueryable<T, T2> reval = CreateInstance<T, T2, ISugarQueryable<T, T2>>(className, currentConnectionConfig.DbType);
return reval;
ISugarQueryable<T, T2> result = CreateInstance<T, T2, ISugarQueryable<T, T2>>(className);
return result;
}
public static ISugarQueryable<T, T2, T3> GetQueryable<T, T2, T3>(ConnectionConfig currentConnectionConfig)
{
string className = "Queryable";
className = GetClassName(currentConnectionConfig.DbType, className);
ISugarQueryable<T, T2, T3> reval = CreateInstance<T, T2, T3, ISugarQueryable<T, T2, T3>>(className, currentConnectionConfig.DbType);
return reval;
ISugarQueryable<T, T2, T3> result = CreateInstance<T, T2, T3, ISugarQueryable<T, T2, T3>>(className);
return result;
}
public static ISugarQueryable<T, T2, T3, T4> GetQueryable<T, T2, T3, T4>(ConnectionConfig currentConnectionConfig)
{
string className = "Queryable";
className = GetClassName(currentConnectionConfig.DbType, className);
ISugarQueryable<T, T2, T3, T4> reval = CreateInstance<T, T2, T3, T4, ISugarQueryable<T, T2, T3, T4>>(className, currentConnectionConfig.DbType);
return reval;
ISugarQueryable<T, T2, T3, T4> result = CreateInstance<T, T2, T3, T4, ISugarQueryable<T, T2, T3, T4>>(className);
return result;
}
public static ISugarQueryable<T, T2, T3, T4, T5> GetQueryable<T, T2, T3, T4, T5>(ConnectionConfig currentConnectionConfig)
{
string className = "Queryable";
className = GetClassName(currentConnectionConfig.DbType, className);
ISugarQueryable<T, T2, T3, T4, T5> reval = CreateInstance<T, T2, T3, T4, T5, ISugarQueryable<T, T2, T3, T4, T5>>(className, currentConnectionConfig.DbType);
return reval;
ISugarQueryable<T, T2, T3, T4, T5> result = CreateInstance<T, T2, T3, T4, T5, ISugarQueryable<T, T2, T3, T4, T5>>(className);
return result;
}
public static ISugarQueryable<T, T2, T3, T4, T5, T6> GetQueryable<T, T2, T3, T4, T5, T6>(ConnectionConfig currentConnectionConfig)
{
string className = "Queryable";
className = GetClassName(currentConnectionConfig.DbType, className);
ISugarQueryable<T, T2, T3, T4, T5, T6> reval = CreateInstance<T, T2, T3, T4, T5, T6, ISugarQueryable<T, T2, T3, T4, T5, T6>>(className, currentConnectionConfig.DbType);
return reval;
ISugarQueryable<T, T2, T3, T4, T5, T6> result = CreateInstance<T, T2, T3, T4, T5, T6, ISugarQueryable<T, T2, T3, T4, T5, T6>>(className);
return result;
}
public static ISugarQueryable<T, T2, T3, T4, T5, T6, T7> GetQueryable<T, T2, T3, T4, T5, T6, T7>(ConnectionConfig currentConnectionConfig)
{
string className = "Queryable";
className = GetClassName(currentConnectionConfig.DbType, className);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> reval = CreateInstance<T, T2, T3, T4, T5, T6, T7, ISugarQueryable<T, T2, T3, T4, T5, T6, T7>>(className, currentConnectionConfig.DbType);
return reval;
ISugarQueryable<T, T2, T3, T4, T5, T6, T7> result = CreateInstance<T, T2, T3, T4, T5, T6, T7, ISugarQueryable<T, T2, T3, T4, T5, T6, T7>>(className);
return result;
}
public static ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> GetQueryable<T, T2, T3, T4, T5, T6, T7, T8>(ConnectionConfig currentConnectionConfig)
{
string className = "Queryable";
className = GetClassName(currentConnectionConfig.DbType, className);
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> reval = CreateInstance<T, T2, T3, T4, T5, T6, T7, T8, ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8>>(className, currentConnectionConfig.DbType);
return reval;
ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> result = CreateInstance<T, T2, T3, T4, T5, T6, T7, T8, ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8>>(className);
return result;
}
#endregion
public static QueryBuilder GetQueryBuilder(ConnectionConfig currentConnectionConfig)
{
QueryBuilder reval = CreateInstance<QueryBuilder>(GetClassName(currentConnectionConfig.DbType, "QueryBuilder"), currentConnectionConfig.DbType);
return reval;
QueryBuilder result = CreateInstance<QueryBuilder>(GetClassName(currentConnectionConfig.DbType, "QueryBuilder"));
return result;
}
public static InsertBuilder GetInsertBuilder(ConnectionConfig currentConnectionConfig)
{
InsertBuilder reval = CreateInstance<InsertBuilder>(GetClassName(currentConnectionConfig.DbType, "InsertBuilder"), currentConnectionConfig.DbType);
return reval;
InsertBuilder result = CreateInstance<InsertBuilder>(GetClassName(currentConnectionConfig.DbType, "InsertBuilder"));
return result;
}
public static UpdateBuilder GetUpdateBuilder(ConnectionConfig currentConnectionConfig)
{
UpdateBuilder reval = CreateInstance<UpdateBuilder>(GetClassName(currentConnectionConfig.DbType, "UpdateBuilder"), currentConnectionConfig.DbType);
return reval;
UpdateBuilder result = CreateInstance<UpdateBuilder>(GetClassName(currentConnectionConfig.DbType, "UpdateBuilder"));
return result;
}
public static DeleteBuilder GetDeleteBuilder(ConnectionConfig currentConnectionConfig)
{
DeleteBuilder reval = CreateInstance<DeleteBuilder>(GetClassName(currentConnectionConfig.DbType, "DeleteBuilder"), currentConnectionConfig.DbType);
return reval;
DeleteBuilder result = CreateInstance<DeleteBuilder>(GetClassName(currentConnectionConfig.DbType, "DeleteBuilder"));
return result;
}
public static ILambdaExpressions GetLambdaExpressions(ConnectionConfig currentConnectionConfig)
{
ILambdaExpressions reval = CreateInstance<ILambdaExpressions>(GetClassName(currentConnectionConfig.DbType, "ExpressionContext"), currentConnectionConfig.DbType);
return reval;
ILambdaExpressions result = CreateInstance<ILambdaExpressions>(GetClassName(currentConnectionConfig.DbType, "ExpressionContext"));
return result;
}
public static ISqlBuilder GetSqlbuilder(ConnectionConfig currentConnectionConfig)
{
ISqlBuilder reval = CreateInstance<ISqlBuilder>(GetClassName(currentConnectionConfig.DbType, "Builder"), currentConnectionConfig.DbType);
return reval;
ISqlBuilder result = CreateInstance<ISqlBuilder>(GetClassName(currentConnectionConfig.DbType, "Builder"));
return result;
}
public static IDbBind GetDbBind(ConnectionConfig currentConnectionConfig)
{
IDbBind reval = CreateInstance<IDbBind>(GetClassName(currentConnectionConfig.DbType, "DbBind"), currentConnectionConfig.DbType);
return reval;
IDbBind result = CreateInstance<IDbBind>(GetClassName(currentConnectionConfig.DbType, "DbBind"));
return result;
}
public static IDbMaintenance GetDbMaintenance(ConnectionConfig currentConnectionConfig)
{
IDbMaintenance reval = CreateInstance<IDbMaintenance>(GetClassName(currentConnectionConfig.DbType, "DbMaintenance"), currentConnectionConfig.DbType);
return reval;
IDbMaintenance result = CreateInstance<IDbMaintenance>(GetClassName(currentConnectionConfig.DbType, "DbMaintenance"));
return result;
}
public static IDbFirst GetDbFirst(ConnectionConfig currentConnectionConfig)
{
IDbFirst reval = CreateInstance<IDbFirst>(GetClassName(currentConnectionConfig.DbType, "DbFirst"), currentConnectionConfig.DbType);
return reval;
IDbFirst result = CreateInstance<IDbFirst>(GetClassName(currentConnectionConfig.DbType, "DbFirst"));
return result;
}
public static ICodeFirst GetCodeFirst(ConnectionConfig currentConnectionConfig)
{
ICodeFirst reval = CreateInstance<ICodeFirst>(GetClassName(currentConnectionConfig.DbType, "CodeFirst"), currentConnectionConfig.DbType);
return reval;
ICodeFirst result = CreateInstance<ICodeFirst>(GetClassName(currentConnectionConfig.DbType, "CodeFirst"));
return result;
}
public static IAdo GetAdo(ConnectionConfig currentConnectionConfig)
{
IAdo reval = CreateInstance<IAdo>(GetClassName(currentConnectionConfig.DbType, "Provider"), currentConnectionConfig.DbType);
return reval;
IAdo result = CreateInstance<IAdo>(GetClassName(currentConnectionConfig.DbType, "Provider"));
return result;
}
private static string GetClassName(string type, string name)
@ -139,170 +139,41 @@ namespace SqlSugar
}
#region CreateInstance
private static Restult CreateInstance<T, Restult>(string className, string dbType)
private static Restult CreateInstance<T, Restult>(string className)
{
var cacheKey = className + typeof(T).FullName;
Type type;
if (typeCache.ContainsKey(cacheKey))
{
type = typeCache[cacheKey];
}
else
{
lock (typeCache)
{
type = Type.GetType(className + "`1", true).MakeGenericType(typeof(T));
Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
if (!typeCache.ContainsKey(cacheKey))
{
typeCache.Add(cacheKey, type);
}
}
}
var reval = (Restult)Activator.CreateInstance(type, true);
return reval;
}
private static Restult CreateInstance<T, T2, Restult>(string className, string dbType)
{
var cacheKey = className + typeof(T).FullName + typeof(T2).FullName;
Type type;
if (typeCache.ContainsKey(cacheKey))
{
type = typeCache[cacheKey];
}
else
{
lock (typeCache)
{
type = Type.GetType(className + "`2", true).MakeGenericType(typeof(T), typeof(T2));
Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
if (!typeCache.ContainsKey(cacheKey))
{
typeCache.Add(cacheKey, type);
}
}
}
var reval = (Restult)Activator.CreateInstance(type, true);
return reval;
}
private static Restult CreateInstance<T, T2, T3, Restult>(string className, string dbType)
{
var cacheKey = className + typeof(T).FullName + typeof(T2).FullName + typeof(T3).FullName;
Type type;
if (typeCache.ContainsKey(cacheKey))
{
type = typeCache[cacheKey];
}
else
{
lock (typeCache)
{
type = Type.GetType(className + "`3", true).MakeGenericType(typeof(T), typeof(T2), typeof(T3));
Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
if (!typeCache.ContainsKey(cacheKey))
{
typeCache.Add(cacheKey, type);
}
}
}
var reval = (Restult)Activator.CreateInstance(type, true);
return reval;
}
private static Restult CreateInstance<T, T2, T3, T4, Restult>(string className, string dbType)
{
var cacheKey = className + typeof(T).FullName + typeof(T2).FullName + typeof(T3).FullName + typeof(T4).FullName;
Type type;
if (typeCache.ContainsKey(cacheKey))
{
type = typeCache[cacheKey];
return CreateInstance<Restult>(className, typeof(T));
}
else
{
lock (typeCache)
{
type = Type.GetType(className + "`4", true).MakeGenericType(typeof(T), typeof(T2), typeof(T3), typeof(T4));
Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
if (!typeCache.ContainsKey(cacheKey))
private static Restult CreateInstance<T, T2, Restult>(string className)
{
typeCache.Add(cacheKey, type);
}
return CreateInstance<Restult>(className, typeof(T), typeof(T2));
}
}
var reval = (Restult)Activator.CreateInstance(type, true);
return reval;
}
private static Restult CreateInstance<T, T2, T3, T4, T5, Restult>(string className, string dbType)
{
var cacheKey = className + typeof(T).FullName + typeof(T2).FullName + typeof(T3).FullName + typeof(T4).FullName + typeof(T5).FullName;
Type type;
if (typeCache.ContainsKey(cacheKey))
private static Restult CreateInstance<T, T2, T3, Restult>(string className)
{
type = typeCache[cacheKey];
return CreateInstance<Restult>(className, typeof(T), typeof(T2), typeof(T3));
}
else
{
lock (typeCache)
{
type = Type.GetType(className + "`5", true).MakeGenericType(typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5));
Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
if (!typeCache.ContainsKey(cacheKey))
private static Restult CreateInstance<T, T2, T3, T4, Restult>(string className)
{
typeCache.Add(cacheKey, type);
}
return CreateInstance<Restult>(className, typeof(T), typeof(T2), typeof(T3), typeof(T4));
}
}
var reval = (Restult)Activator.CreateInstance(type, true);
return reval;
}
private static Restult CreateInstance<T, T2, T3, T4, T5, T6, Restult>(string className, string dbType)
private static Restult CreateInstance<T, T2, T3, T4, T5, Restult>(string className)
{
var cacheKey = className + typeof(T).FullName + typeof(T2).FullName + typeof(T3).FullName + typeof(T4).FullName + typeof(T5).FullName + typeof(T6).FullName;
Type type;
if (typeCache.ContainsKey(cacheKey))
{
type = typeCache[cacheKey];
return CreateInstance<Restult>(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5));
}
else
{
lock (typeCache)
{
type = Type.GetType(className + "`6", true).MakeGenericType(typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6));
Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
if (!typeCache.ContainsKey(cacheKey))
private static Restult CreateInstance<T, T2, T3, T4, T5, T6, Restult>(string className)
{
typeCache.Add(cacheKey, type);
}
return CreateInstance<Restult>(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5),typeof(T6));
}
}
var reval = (Restult)Activator.CreateInstance(type, true);
return reval;
}
private static Restult CreateInstance<T, T2, T3, T4, T5, T6, T7, Restult>(string className, string dbType)
private static Restult CreateInstance<T, T2, T3, T4, T5, T6, T7, Restult>(string className)
{
var cacheKey = className + typeof(T).FullName + typeof(T2).FullName + typeof(T3).FullName + typeof(T4).FullName + typeof(T5).FullName + typeof(T6).FullName + typeof(T7).FullName;
Type type;
if (typeCache.ContainsKey(cacheKey))
{
type = typeCache[cacheKey];
return CreateInstance< Restult > (className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5),typeof(T6),typeof(T7));
}
else
private static Restult CreateInstance<T, T2, T3, T4, T5, T6, T7, T8, Restult>(string className)
{
lock (typeCache)
{
type = Type.GetType(className + "`7", true).MakeGenericType(typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7));
Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
if (!typeCache.ContainsKey(cacheKey))
{
typeCache.Add(cacheKey, type);
}
}
}
var reval = (Restult)Activator.CreateInstance(type, true);
return reval;
return CreateInstance<Restult>(className, typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7),typeof(T8));
}
private static Restult CreateInstance<T, T2, T3, T4, T5, T6, T7, T8, Restult>(string className, string dbType)
private static Restult CreateInstance<Restult>(string className, params Type[] types)
{
var cacheKey = className + typeof(T).FullName + typeof(T2).FullName + typeof(T3).FullName + typeof(T4).FullName + typeof(T5).FullName + typeof(T6).FullName + typeof(T7).FullName + typeof(T8).FullName;
var cacheKey = className + string.Join(",", types.Select(it => it.FullName));
Type type;
if (typeCache.ContainsKey(cacheKey))
{
@ -312,7 +183,7 @@ namespace SqlSugar
{
lock (typeCache)
{
type = Type.GetType(className + "`8", true).MakeGenericType(typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8));
type = Type.GetType(className + "`" + types.Length, true).MakeGenericType(types);
Check.ArgumentNullException(type, string.Format(ErrorMessage.ObjNotExist, className));
if (!typeCache.ContainsKey(cacheKey))
{
@ -320,10 +191,10 @@ namespace SqlSugar
}
}
}
var reval = (Restult)Activator.CreateInstance(type, true);
return reval;
var result = (Restult)Activator.CreateInstance(type, true);
return result;
}
private static T CreateInstance<T>(string className, string dbType)
private static T CreateInstance<T>(string className)
{
Type type;
if (typeCache.ContainsKey(className))
@ -342,8 +213,8 @@ namespace SqlSugar
}
}
}
var reval = (T)Activator.CreateInstance(type, true);
return reval;
var result = (T)Activator.CreateInstance(type, true);
return result;
}
#endregion
}

Loading…
Cancel
Save