SimpleClient.CopyNew()

This commit is contained in:
sunkaixuan 2023-03-15 23:43:35 +08:00
parent 6117c01e70
commit 02b13d8edc
2 changed files with 18 additions and 0 deletions

View File

@ -7,6 +7,7 @@ namespace SqlSugar
{
public interface ISimpleClient<T> where T : class, new()
{
RepositoryType CopyNew<RepositoryType>() where RepositoryType : ISugarRepository;
SimpleClient<ChangeType> Change<ChangeType>() where ChangeType : class, new();
RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository ;
IDeleteable<T> AsDeleteable();

View File

@ -35,6 +35,23 @@ namespace SqlSugar
{
return this.Context.GetSimpleClient<ChangeType>();
}
public RepositoryType CopyNew<RepositoryType>() where RepositoryType : ISugarRepository
{
Type type = typeof(RepositoryType);
var isAnyParamter = type.GetConstructors().Any(z => z.GetParameters().Any());
object o = null;
if (isAnyParamter)
{
o = Activator.CreateInstance(type, new string[] { null });
}
else
{
o = Activator.CreateInstance(type);
}
var result = (RepositoryType)o;
result.Context = this.Context.CopyNew();
return result;
}
public RepositoryType ChangeRepository<RepositoryType>() where RepositoryType : ISugarRepository
{
Type type = typeof(RepositoryType);