Delegate to type specific Action

This commit is contained in:
ousttrue
2019-01-29 14:48:39 +09:00
parent 4d94ca9751
commit b6303ea26b
4 changed files with 27 additions and 27 deletions

View File

@@ -49,13 +49,13 @@ namespace UniJSON
var a = String.Join(", ", GetArgs("a", i).ToArray());
var source = @"
public static Delegate Create<S, $0>(MethodInfo m)
public static Action<S, $0> Create<S, $0>(MethodInfo m)
{
var self = Expression.Parameter(m.DeclaringType, m.Name);
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
var call = Expression.Call(self, m, args);
return
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
(Action<S, $0>)Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
}
".Replace("$0", g).Replace("$1", a);
@@ -68,7 +68,7 @@ namespace UniJSON
var g = String.Join(", ", GetArgs("A", i).ToArray());
var source = @"
public static Delegate CreateWithThis<S, $0>(MethodInfo m, S instance)
public static Action<$0> CreateWithThis<S, $0>(MethodInfo m, S instance)
{
if (m.IsStatic)
{
@@ -97,7 +97,7 @@ namespace UniJSON
call = Expression.Call(self, m, args);
}
return
Expression.Lambda(call, args).Compile();
(Action<$0>)Expression.Lambda(call, args).Compile();
}
".Replace("$0", g);

View File

@@ -11,37 +11,37 @@ namespace UniJSON
{
public static Delegate Create<S, A0>(MethodInfo m)
public static Action<S, A0> Create<S, A0>(MethodInfo m)
{
var self = Expression.Parameter(m.DeclaringType, m.Name);
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
var call = Expression.Call(self, m, args);
return
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
(Action<S, A0>)Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
}
public static Delegate Create<S, A0, A1>(MethodInfo m)
public static Action<S, A0, A1> Create<S, A0, A1>(MethodInfo m)
{
var self = Expression.Parameter(m.DeclaringType, m.Name);
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
var call = Expression.Call(self, m, args);
return
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
(Action<S, A0, A1>)Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
}
public static Delegate Create<S, A0, A1, A2>(MethodInfo m)
public static Action<S, A0, A1, A2> Create<S, A0, A1, A2>(MethodInfo m)
{
var self = Expression.Parameter(m.DeclaringType, m.Name);
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
var call = Expression.Call(self, m, args);
return
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
(Action<S, A0, A1, A2>)Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
}
public static Delegate CreateWithThis<S, A0>(MethodInfo m, S instance)
public static Action<A0> CreateWithThis<S, A0>(MethodInfo m, S instance)
{
if (m.IsStatic)
{
@@ -70,11 +70,11 @@ namespace UniJSON
call = Expression.Call(self, m, args);
}
return
Expression.Lambda(call, args).Compile();
(Action<A0>)Expression.Lambda(call, args).Compile();
}
public static Delegate CreateWithThis<S, A0, A1>(MethodInfo m, S instance)
public static Action<A0, A1> CreateWithThis<S, A0, A1>(MethodInfo m, S instance)
{
if (m.IsStatic)
{
@@ -103,11 +103,11 @@ namespace UniJSON
call = Expression.Call(self, m, args);
}
return
Expression.Lambda(call, args).Compile();
(Action<A0, A1>)Expression.Lambda(call, args).Compile();
}
public static Delegate CreateWithThis<S, A0, A1, A2>(MethodInfo m, S instance)
public static Action<A0, A1, A2> CreateWithThis<S, A0, A1, A2>(MethodInfo m, S instance)
{
if (m.IsStatic)
{
@@ -136,11 +136,11 @@ namespace UniJSON
call = Expression.Call(self, m, args);
}
return
Expression.Lambda(call, args).Compile();
(Action<A0, A1, A2>)Expression.Lambda(call, args).Compile();
}
public static Delegate CreateWithThis<S, A0, A1, A2, A3>(MethodInfo m, S instance)
public static Action<A0, A1, A2, A3> CreateWithThis<S, A0, A1, A2, A3>(MethodInfo m, S instance)
{
if (m.IsStatic)
{
@@ -169,7 +169,7 @@ namespace UniJSON
call = Expression.Call(self, m, args);
}
return
Expression.Lambda(call, args).Compile();
(Action<A0, A1, A2, A3>)Expression.Lambda(call, args).Compile();
}

View File

@@ -54,7 +54,7 @@ namespace UniJSON
var source = @"
public static Delegate Create<S, $0>(MethodInfo m)
public static Action<S, $0> Create<S, $0>(MethodInfo m)
{
Action<S, $0> callback=
(s, $1) =>
@@ -78,7 +78,7 @@ namespace UniJSON
var a = String.Join(", ", GetArgs("a", i).ToArray());
var source = @"
public static Delegate CreateWithThis<S, $0>(MethodInfo m, S instance)
public static Action<$0> CreateWithThis<S, $0>(MethodInfo m, S instance)
{
if (m.IsStatic)
{

View File

@@ -10,7 +10,7 @@ namespace UniJSON
//////////// Create
public static Delegate Create<S, A0>(MethodInfo m)
public static Action<S, A0> Create<S, A0>(MethodInfo m)
{
Action<S, A0> callback=
(s, a0) =>
@@ -21,7 +21,7 @@ namespace UniJSON
}
public static Delegate Create<S, A0, A1>(MethodInfo m)
public static Action<S, A0, A1> Create<S, A0, A1>(MethodInfo m)
{
Action<S, A0, A1> callback=
(s, a0, a1) =>
@@ -32,7 +32,7 @@ namespace UniJSON
}
public static Delegate Create<S, A0, A1, A2>(MethodInfo m)
public static Action<S, A0, A1, A2> Create<S, A0, A1, A2>(MethodInfo m)
{
Action<S, A0, A1, A2> callback=
(s, a0, a1, a2) =>
@@ -44,7 +44,7 @@ namespace UniJSON
//////////// CreateWithThis
public static Delegate CreateWithThis<S, A0>(MethodInfo m, S instance)
public static Action<A0> CreateWithThis<S, A0>(MethodInfo m, S instance)
{
if (m.IsStatic)
{
@@ -70,7 +70,7 @@ namespace UniJSON
}
public static Delegate CreateWithThis<S, A0, A1>(MethodInfo m, S instance)
public static Action<A0, A1> CreateWithThis<S, A0, A1>(MethodInfo m, S instance)
{
if (m.IsStatic)
{
@@ -96,7 +96,7 @@ namespace UniJSON
}
public static Delegate CreateWithThis<S, A0, A1, A2>(MethodInfo m, S instance)
public static Action<A0, A1, A2> CreateWithThis<S, A0, A1, A2>(MethodInfo m, S instance)
{
if (m.IsStatic)
{
@@ -122,7 +122,7 @@ namespace UniJSON
}
public static Delegate CreateWithThis<S, A0, A1, A2, A3>(MethodInfo m, S instance)
public static Action<A0, A1, A2, A3> CreateWithThis<S, A0, A1, A2, A3>(MethodInfo m, S instance)
{
if (m.IsStatic)
{