Synchronization code

This commit is contained in:
sunkaixuan 2023-06-03 19:56:36 +08:00
parent 499a14a9bf
commit 311c6aaaf2
4 changed files with 81 additions and 7 deletions

View File

@ -8,7 +8,53 @@ namespace SqlSugar
{ {
public class CommonMethodInfo public class CommonMethodInfo
{ {
internal object Context { get; set; } internal object Context { get; set; }
public int ExecuteReturnIdentity()
{
if (Context == null) return 0;
var result = Context.GetType().GetMyMethod("ExecuteReturnIdentity", 0).Invoke(Context, new object[] { });
return (int)result;
}
public async Task<int> ExecuteReturnIdentityAsync()
{
if (Context == null) return 0;
var result = Context.GetType().GetMyMethod("ExecuteReturnIdentityAsync", 0).Invoke(Context, new object[] { });
return await (Task<int>)result;
}
public int ExecuteCommand()
{
if (Context == null) return 0;
var result = Context.GetType().GetMyMethod("ExecuteCommand", 0).Invoke(Context, new object[] { });
return (int)result;
}
public async Task<int> ExecuteCommandAsync()
{
if (Context == null) return 0;
var result = Context.GetType().GetMyMethod("ExecuteCommandAsync", 0).Invoke(Context, new object[] { });
return await (Task<int>)result;
}
}
public class SplitMethodInfo
{
internal object Context { get; set; }
public int ExecuteCommand()
{
if (Context == null) return 0;
var result = Context.GetType().GetMyMethod("ExecuteCommand", 0).Invoke(Context, new object[] { });
return (int)result;
}
public async Task<int> ExecuteCommandAsync()
{
if (Context == null) return 0;
var result = Context.GetType().GetMyMethod("ExecuteCommandAsync", 0).Invoke(Context, new object[] { });
return await (Task<int>)result;
}
}
public class UpdateCommonMethodInfo
{
internal object Context { get; set; }
public int ExecuteCommand() public int ExecuteCommand()
{ {

View File

@ -11,7 +11,7 @@ namespace SqlSugar
{ {
internal SqlSugarProvider Context { get; set; } internal SqlSugarProvider Context { get; set; }
internal MethodInfo MethodInfo { get; set; } internal MethodInfo MethodInfo { get; set; }
internal object objectValue { get; set; } internal object objectValue { get; set; }
public int ExecuteCommand() public int ExecuteCommand()
{ {
@ -41,12 +41,24 @@ namespace SqlSugar
var result = inertable.GetType().GetMyMethod("ExecuteReturnIdentityAsync",0).Invoke(inertable, new object[] { }); var result = inertable.GetType().GetMyMethod("ExecuteReturnIdentityAsync",0).Invoke(inertable, new object[] { });
return await (Task<int>)result; return await (Task<int>)result;
} }
public CommonMethodInfo SplitTable()
public CommonMethodInfo IgnoreColumns(params string [] ignoreColumns)
{
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var newMethod = inertable.GetType().GetMyMethod("IgnoreColumns", 1, typeof(string[]));
var result = newMethod.Invoke(inertable, new object[] { ignoreColumns });
return new CommonMethodInfo()
{
Context = result
};
}
public SplitMethodInfo SplitTable()
{ {
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue }); var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var newMethod = inertable.GetType().GetMyMethod("SplitTable", 0); var newMethod = inertable.GetType().GetMyMethod("SplitTable", 0);
var result = newMethod.Invoke(inertable, new object[] { }); var result = newMethod.Invoke(inertable, new object[] { });
return new CommonMethodInfo() return new SplitMethodInfo()
{ {
Context = result Context = result
}; };

View File

@ -28,13 +28,22 @@ namespace SqlSugar
var result = inertable.GetType().GetMyMethod("ExecuteCommandAsync",0).Invoke(inertable, new object[] { }); var result = inertable.GetType().GetMyMethod("ExecuteCommandAsync",0).Invoke(inertable, new object[] { });
return await (Task<int>)result; return await (Task<int>)result;
} }
public UpdateCommonMethodInfo IgnoreColumns(params string[] ignoreColumns)
public CommonMethodInfo SplitTable() {
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var newMethod = inertable.GetType().GetMyMethod("IgnoreColumns", 1,typeof(string[]));
var result = newMethod.Invoke(inertable, new object[] { ignoreColumns });
return new UpdateCommonMethodInfo()
{
Context = result
};
}
public UpdateCommonMethodInfo SplitTable()
{ {
var inertable = MethodInfo.Invoke(Context, new object[] { objectValue }); var inertable = MethodInfo.Invoke(Context, new object[] { objectValue });
var newMethod = inertable.GetType().GetMyMethod("SplitTable", 0); var newMethod = inertable.GetType().GetMyMethod("SplitTable", 0);
var result = newMethod.Invoke(inertable, new object[] { }); var result = newMethod.Invoke(inertable, new object[] { });
return new CommonMethodInfo() return new UpdateCommonMethodInfo()
{ {
Context = result Context = result
}; };

View File

@ -25,6 +25,13 @@ namespace SqlSugar
{ {
return type.GetMethods().FirstOrDefault(it => it.Name == name && it.GetParameters().Length == argCount); return type.GetMethods().FirstOrDefault(it => it.Name == name && it.GetParameters().Length == argCount);
} }
public static MethodInfo GetMyMethod(this Type type, string name, int argCount,Type parameterType)
{
return type.GetMethods().FirstOrDefault(it =>
it.Name == name &&
it.GetParameters().Length == argCount&&
it.GetParameters().First().ParameterType==parameterType);
}
public static List<T> ToList<T>(this T thisValue,Func<T,T> action) where T:class,new() public static List<T> ToList<T>(this T thisValue,Func<T,T> action) where T:class,new()
{ {
return new List<T> { thisValue }; return new List<T> { thisValue };