using System; using System.Linq; using System.Linq.Expressions; using System.Reflection; namespace UniJSON { public static partial class GenericExpressionCallFactory { #if UNITY_5 public static Delegate Create(MethodInfo m) #else public static Action Create(MethodInfo m) #endif { 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 #if UNITY_5 #else (Action) #endif Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile(); } #if UNITY_5 public static Delegate Create(MethodInfo m) #else public static Action Create(MethodInfo m) #endif { 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 #if UNITY_5 #else (Action) #endif Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile(); } #if UNITY_5 public static Delegate Create(MethodInfo m) #else public static Action Create(MethodInfo m) #endif { 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 #if UNITY_5 #else (Action) #endif Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile(); } #if UNITY_5 public static Delegate Create(MethodInfo m) #else public static Action Create(MethodInfo m) #endif { 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 #if UNITY_5 #else (Action) #endif Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile(); } #if UNITY_5 public static Delegate Create(MethodInfo m) #else public static Action Create(MethodInfo m) #endif { 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 #if UNITY_5 #else (Action) #endif Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile(); } #if UNITY_5 public static Delegate Create(MethodInfo m) #else public static Action Create(MethodInfo m) #endif { 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 #if UNITY_5 #else (Action) #endif Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile(); } #if UNITY_5 public static Delegate CreateWithThis(MethodInfo m, S instance) #else public static Action CreateWithThis(MethodInfo m, S instance) #endif { if (m.IsStatic) { if (instance != null) { throw new ArgumentException(); } } else { if (instance == null) { throw new ArgumentNullException(); } } var self = Expression.Constant(instance, typeof(S)); // thisを定数化 var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray(); MethodCallExpression call; if (m.IsStatic) { call = Expression.Call(m, args); } else { call = Expression.Call(self, m, args); } return #if UNITY_5 #else (Action) #endif Expression.Lambda(call, args).Compile(); } #if UNITY_5 public static Delegate CreateWithThis(MethodInfo m, S instance) #else public static Action CreateWithThis(MethodInfo m, S instance) #endif { if (m.IsStatic) { if (instance != null) { throw new ArgumentException(); } } else { if (instance == null) { throw new ArgumentNullException(); } } var self = Expression.Constant(instance, typeof(S)); // thisを定数化 var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray(); MethodCallExpression call; if (m.IsStatic) { call = Expression.Call(m, args); } else { call = Expression.Call(self, m, args); } return #if UNITY_5 #else (Action) #endif Expression.Lambda(call, args).Compile(); } #if UNITY_5 public static Delegate CreateWithThis(MethodInfo m, S instance) #else public static Action CreateWithThis(MethodInfo m, S instance) #endif { if (m.IsStatic) { if (instance != null) { throw new ArgumentException(); } } else { if (instance == null) { throw new ArgumentNullException(); } } var self = Expression.Constant(instance, typeof(S)); // thisを定数化 var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray(); MethodCallExpression call; if (m.IsStatic) { call = Expression.Call(m, args); } else { call = Expression.Call(self, m, args); } return #if UNITY_5 #else (Action) #endif Expression.Lambda(call, args).Compile(); } #if UNITY_5 public static Delegate CreateWithThis(MethodInfo m, S instance) #else public static Action CreateWithThis(MethodInfo m, S instance) #endif { if (m.IsStatic) { if (instance != null) { throw new ArgumentException(); } } else { if (instance == null) { throw new ArgumentNullException(); } } var self = Expression.Constant(instance, typeof(S)); // thisを定数化 var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray(); MethodCallExpression call; if (m.IsStatic) { call = Expression.Call(m, args); } else { call = Expression.Call(self, m, args); } return #if UNITY_5 #else (Action) #endif Expression.Lambda(call, args).Compile(); } #if UNITY_5 public static Delegate CreateWithThis(MethodInfo m, S instance) #else public static Action CreateWithThis(MethodInfo m, S instance) #endif { if (m.IsStatic) { if (instance != null) { throw new ArgumentException(); } } else { if (instance == null) { throw new ArgumentNullException(); } } var self = Expression.Constant(instance, typeof(S)); // thisを定数化 var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray(); MethodCallExpression call; if (m.IsStatic) { call = Expression.Call(m, args); } else { call = Expression.Call(self, m, args); } return #if UNITY_5 #else (Action) #endif Expression.Lambda(call, args).Compile(); } #if UNITY_5 public static Delegate CreateWithThis(MethodInfo m, S instance) #else public static Action CreateWithThis(MethodInfo m, S instance) #endif { if (m.IsStatic) { if (instance != null) { throw new ArgumentException(); } } else { if (instance == null) { throw new ArgumentNullException(); } } var self = Expression.Constant(instance, typeof(S)); // thisを定数化 var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray(); MethodCallExpression call; if (m.IsStatic) { call = Expression.Call(m, args); } else { call = Expression.Call(self, m, args); } return #if UNITY_5 #else (Action) #endif Expression.Lambda(call, args).Compile(); } } }