mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-31 15:56:25 +08:00
Synchronization code
This commit is contained in:
parent
5ff7554497
commit
37adfd52ee
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class StorageableMethodInfo
|
||||
{
|
||||
internal SqlSugarProvider Context { get; set; }
|
||||
internal MethodInfo MethodInfo { get; set; }
|
||||
internal object objectValue { get; set; }
|
||||
public int ExecuteCommand()
|
||||
{
|
||||
if (Context == null) return 0;
|
||||
object objectValue = null;
|
||||
MethodInfo method = GetSaveMethod(ref objectValue);
|
||||
return (int)method.Invoke(objectValue, new object[] { });
|
||||
}
|
||||
|
||||
public StorageableAsMethodInfo AsInsertable
|
||||
{
|
||||
get
|
||||
{
|
||||
var type = "AsInsertable";
|
||||
return GetAs(type);
|
||||
}
|
||||
}
|
||||
public StorageableAsMethodInfo AsUpdateable
|
||||
{
|
||||
get
|
||||
{
|
||||
var type = "AsUpdateable";
|
||||
return GetAs(type);
|
||||
}
|
||||
}
|
||||
|
||||
private StorageableAsMethodInfo GetAs(string type)
|
||||
{
|
||||
object objectValue = null;
|
||||
MethodInfo method = GetSaveMethod(ref objectValue);
|
||||
method = objectValue.GetType().GetMethod("ToStorage");
|
||||
objectValue = method.Invoke(objectValue, new object[] { });
|
||||
StorageableAsMethodInfo result = new StorageableAsMethodInfo(type);
|
||||
result.ObjectValue = objectValue;
|
||||
result.Method = method;
|
||||
return result;
|
||||
}
|
||||
|
||||
private MethodInfo GetSaveMethod(ref object callValue)
|
||||
{
|
||||
callValue = MethodInfo.Invoke(Context, new object[] { objectValue });
|
||||
return callValue.GetType().GetMethod("ExecuteCommand");
|
||||
}
|
||||
|
||||
public StorageableMethodInfo ToStorage()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public class StorageableAsMethodInfo
|
||||
{
|
||||
private StorageableAsMethodInfo() { }
|
||||
private string type;
|
||||
public StorageableAsMethodInfo(string type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
internal object ObjectValue { get; set; }
|
||||
internal MethodInfo Method { get; set; }
|
||||
public int ExecuteCommand()
|
||||
{
|
||||
PropertyInfo property = ObjectValue.GetType().GetProperty(type);
|
||||
var value = property.GetValue(ObjectValue);
|
||||
var newObj= value.GetType().GetMethod("ExecuteCommand").Invoke(value, new object[] { });
|
||||
return (int)newObj;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
@ -869,6 +871,52 @@ namespace SqlSugar
|
||||
data.Columns.Add(new DataColumn("SugarColumns", typeof(string[])));
|
||||
return result;
|
||||
}
|
||||
public StorageableMethodInfo StorageableByObject(object singleEntityObjectOrList)
|
||||
{
|
||||
if (singleEntityObjectOrList == null)
|
||||
return new StorageableMethodInfo();
|
||||
if (singleEntityObjectOrList.GetType().FullName.IsCollectionsList())
|
||||
{
|
||||
var list = ((IList)singleEntityObjectOrList);
|
||||
if(list==null|| list.Count==0)
|
||||
return new StorageableMethodInfo();
|
||||
var type=list[0].GetType();
|
||||
var newList = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(type)) ;
|
||||
foreach (var item in list)
|
||||
{
|
||||
newList.Add(item);
|
||||
}
|
||||
var methods = this.Context.GetType().GetMethods()
|
||||
.Where(it => it.Name == "Storageable")
|
||||
.Where(it => it.GetGenericArguments().Any())
|
||||
.Where(it => it.GetParameters().Any(z => z.ParameterType.Name.StartsWith("List")))
|
||||
.Where(it => it.Name == "Storageable").ToList();
|
||||
var method = methods.Single().MakeGenericMethod(newList.GetType().GetGenericArguments().First());
|
||||
StorageableMethodInfo result = new StorageableMethodInfo()
|
||||
{
|
||||
Context = this.Context,
|
||||
MethodInfo = method,
|
||||
objectValue = newList
|
||||
};
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
var methods = this.Context.GetType().GetMethods()
|
||||
.Where(it => it.Name == "Storageable")
|
||||
.Where(it => it.GetGenericArguments().Any())
|
||||
.Where(it => it.GetParameters().Any(z => z.ParameterType.Name == "T"))
|
||||
.Where(it => it.Name == "Storageable").ToList();
|
||||
var method = methods.Single().MakeGenericMethod(singleEntityObjectOrList.GetType());
|
||||
StorageableMethodInfo result = new StorageableMethodInfo()
|
||||
{
|
||||
Context = this.Context,
|
||||
MethodInfo = method,
|
||||
objectValue = singleEntityObjectOrList
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Reportable
|
||||
|
@ -588,6 +588,10 @@ namespace SqlSugar
|
||||
{
|
||||
return ScopedContext.Storageable(data);
|
||||
}
|
||||
public StorageableMethodInfo StorageableByObject(object singleEntityObjectOrListObject)
|
||||
{
|
||||
return ScopedContext.StorageableByObject(singleEntityObjectOrListObject);
|
||||
}
|
||||
|
||||
public ISugarQueryable<T> Union<T>(List<ISugarQueryable<T>> queryables) where T : class, new()
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Dynamic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
@ -146,6 +147,9 @@ namespace SqlSugar
|
||||
ISaveable<T> Saveable<T>(List<T> saveObjects) where T : class, new();
|
||||
[Obsolete("use Storageable")]
|
||||
ISaveable<T> Saveable<T>(T saveObject) where T : class, new();
|
||||
|
||||
StorageableMethodInfo StorageableByObject(object singleEntityObjectOrListObject);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Queue
|
||||
|
@ -538,6 +538,10 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.Saveable(saveObject);
|
||||
}
|
||||
public StorageableMethodInfo StorageableByObject(object singleEntityObjectOrListObject)
|
||||
{
|
||||
return this.Context.StorageableByObject(singleEntityObjectOrListObject);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Reportable
|
||||
|
@ -599,6 +599,10 @@ namespace SqlSugar
|
||||
{
|
||||
return ScopedContext.Storageable(data);
|
||||
}
|
||||
public StorageableMethodInfo StorageableByObject(object singleEntityObjectOrListObject)
|
||||
{
|
||||
return this.ScopedContext.StorageableByObject(singleEntityObjectOrListObject);
|
||||
}
|
||||
|
||||
public ISugarQueryable<T> Union<T>(List<ISugarQueryable<T>> queryables) where T : class, new()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user