From 9da1b3f321ecfbf431789f8a324d54e2c8fb1019 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 28 Jan 2019 16:12:37 +0900 Subject: [PATCH] Added GenericCallUtility --- .../Editor/Tests/GenericCallUtilityTests.cs | 43 ++ .../Tests/GenericCallUtilityTests.cs.meta | 12 + .../UniJSON/Scripts/GenericCallUtility.meta | 9 + .../GenericExpressionCallFactory.cs | 134 +++++++ .../GenericExpressionCallFactory.cs.meta | 11 + .../GenericExpressionCallFactory.g.cs | 370 ++++++++++++++++++ .../GenericExpressionCallFactory.g.cs.meta | 11 + .../GenericInvokeCallFactory.cs | 164 ++++++++ .../GenericInvokeCallFactory.cs.meta | 11 + .../GenericInvokeCallFactory.g.cs | 321 +++++++++++++++ .../GenericInvokeCallFactory.g.cs.meta | 11 + UniJSON35/UniJSON/UniJSON.csproj | 4 +- 12 files changed, 1099 insertions(+), 2 deletions(-) create mode 100644 Assets/VRM/UniJSON/Editor/Tests/GenericCallUtilityTests.cs create mode 100644 Assets/VRM/UniJSON/Editor/Tests/GenericCallUtilityTests.cs.meta create mode 100644 Assets/VRM/UniJSON/Scripts/GenericCallUtility.meta create mode 100644 Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.cs create mode 100644 Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.cs.meta create mode 100644 Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.g.cs create mode 100644 Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.g.cs.meta create mode 100644 Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.cs create mode 100644 Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.cs.meta create mode 100644 Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.g.cs create mode 100644 Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.g.cs.meta diff --git a/Assets/VRM/UniJSON/Editor/Tests/GenericCallUtilityTests.cs b/Assets/VRM/UniJSON/Editor/Tests/GenericCallUtilityTests.cs new file mode 100644 index 0000000000..9a6f73b22f --- /dev/null +++ b/Assets/VRM/UniJSON/Editor/Tests/GenericCallUtilityTests.cs @@ -0,0 +1,43 @@ +using UnityEngine; +using NUnit.Framework; +using System.Collections; +using System; + + +namespace UniJSON +{ + public class GenericCallUtilityTests + { + class Sample + { + public int Value + { + get; + private set; + } + + public void Set(int value) + { + Value = value; + } + } + + + + [Test] + public void GenericCallUtilityTestsSimplePasses() + { + var s = new Sample(); + + var mi = s.GetType().GetMethod("Set"); + + var invoke = (Action)GenericInvokeCallFactory.Create(mi); + invoke(s, 1); + Assert.AreEqual(1, s.Value); + + var exp = (Action)GenericExpressionCallFactory.Create(mi); + exp(s, 2); + Assert.AreEqual(2, s.Value); + } + } +} diff --git a/Assets/VRM/UniJSON/Editor/Tests/GenericCallUtilityTests.cs.meta b/Assets/VRM/UniJSON/Editor/Tests/GenericCallUtilityTests.cs.meta new file mode 100644 index 0000000000..f581604878 --- /dev/null +++ b/Assets/VRM/UniJSON/Editor/Tests/GenericCallUtilityTests.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 961cb5c87e54b5d4685e7447783259e7 +timeCreated: 1548657517 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniJSON/Scripts/GenericCallUtility.meta b/Assets/VRM/UniJSON/Scripts/GenericCallUtility.meta new file mode 100644 index 0000000000..dc2833ab0a --- /dev/null +++ b/Assets/VRM/UniJSON/Scripts/GenericCallUtility.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 1a508fceebf4ef64ca956059360b2467 +folderAsset: yes +timeCreated: 1548656168 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.cs b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.cs new file mode 100644 index 0000000000..03ff440171 --- /dev/null +++ b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.cs @@ -0,0 +1,134 @@ +using System; +using System.IO; +using System.Linq; +using System.Text; +#if UNITY_EDITOR +using UnityEditor; +#endif + + +namespace UniJSON +{ + public static partial class GenericExpressionCallFactory + { +#if UNITY_EDITOR && VRM_DEVELOP + const int ARGS = 6; + const string GENERATE_PATH = "Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.g.cs"; + + static System.Collections.Generic.IEnumerable GetArgs(string prefix, int n) + { + for (int i = 0; i < n; ++i) + { + yield return prefix + i; + } + } + + [MenuItem(VRM.VRMVersion.MENU + "/Generate GenericExpressionCallFactory")] + static void Generate() + { + var sb = new StringBuilder(); + using (var w = new StringWriter(sb)) + { + w.WriteLine(@" +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + + +namespace UniJSON +{ + public static partial class GenericExpressionCallFactory + { +"); + // Create + for (int i = 1; i <= ARGS; ++i) + { + var g = String.Join(", ", GetArgs("A", i).ToArray()); + var a = String.Join(", ", GetArgs("a", i).ToArray()); + + var source = @" +#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(); + } +".Replace("$0", g).Replace("$1", a); + + w.WriteLine(source); + } + + // CreateWithThis + for (int i = 1; i <= ARGS; ++i) + { + var g = String.Join(", ", GetArgs("A", i).ToArray()); + + var source = @" +#if UNITY_5 + public static Delegate CreateWithThis(MethodInfo m, S instance) +#else + public static Action<$0> 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<$0>) +#endif + Expression.Lambda(call, args).Compile(); + } +".Replace("$0", g); + + w.WriteLine(source); + } + + w.WriteLine(@" + } +} +"); + } + + var path = UniGLTF.UnityPath.FromUnityPath(GENERATE_PATH); + File.WriteAllText(path.FullPath, sb.ToString().Replace("\r\n", "\n")); + path.ImportAsset(); + } +#endif + } +} diff --git a/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.cs.meta b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.cs.meta new file mode 100644 index 0000000000..85eef34b6f --- /dev/null +++ b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 93b8e65929169944e823bc9a95c8a1ed +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.g.cs b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.g.cs new file mode 100644 index 0000000000..30f647b0de --- /dev/null +++ b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.g.cs @@ -0,0 +1,370 @@ + +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(); + } + + + } +} + diff --git a/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.g.cs.meta b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.g.cs.meta new file mode 100644 index 0000000000..50a6f0d294 --- /dev/null +++ b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.g.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cf88d89ec3acdbf4eb44842ed15aaff4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.cs b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.cs new file mode 100644 index 0000000000..2a34544c67 --- /dev/null +++ b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.cs @@ -0,0 +1,164 @@ +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +#if UNITY_EDITOR +using UnityEditor; +#endif + + +namespace UniJSON +{ + public static partial class GenericInvokeCallFactory + { +#if UNITY_EDITOR && VRM_DEVELOP + const int ARGS = 6; + const string GENERATE_PATH = "Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.g.cs"; + + static System.Collections.Generic.IEnumerable GetArgs(string prefix, int n) + { + for (int i = 0; i < n; ++i) + { + yield return prefix + i; + } + } + + [MenuItem(VRM.VRMVersion.MENU + "/Generate GenericInvokeCallFactory")] + static void Generate() + { + var sb = new StringBuilder(); + using (var w = new StringWriter(sb)) + { + w.WriteLine(@" +using System; +using System.Reflection; + + +namespace UniJSON +{ + public static partial class GenericInvokeCallFactory + { +"); + + // CreateWithThis + w.WriteLine("//////////// Create"); + + // Create + for (int i = 1; i <= ARGS; ++i) + { + var g = String.Join(", ", GetArgs("A", i).ToArray()); + var a = String.Join(", ", GetArgs("a", i).ToArray()); + + if (i >= 4) w.WriteLine(@" +#if UNITY_5 +#else +"); + + + var source = @" +#if UNITY_5 + public static Delegate Create(MethodInfo m) +#else + public static Action Create(MethodInfo m) +#endif + { + Action callback= + (s, $1) => + { + m.Invoke(s, new object[] { $1 }); + }; + return callback; + } +".Replace("$0", g).Replace("$1", a); + + w.WriteLine(source); + + if (i >= 4) w.WriteLine(@" +#endif +"); + } + + + // CreateWithThis + w.WriteLine("//////////// CreateWithThis"); + for (int i = 1; i <= ARGS; ++i) + { + var g = String.Join(", ", GetArgs("A", i).ToArray()); + var a = String.Join(", ", GetArgs("a", i).ToArray()); + + if (i > 4) w.WriteLine(@" +#if UNITY_5 +#else +"); + + var source = @" +#if UNITY_5 + public static Delegate CreateWithThis(MethodInfo m, S instance) +#else + public static Action<$0> CreateWithThis(MethodInfo m, S instance) +#endif + { + if (m.IsStatic) + { + if (instance != null) + { + throw new ArgumentException(); + } + } + else + { + if (instance == null) + { + throw new ArgumentNullException(); + } + } + + // ToDo: CreateDelegate + Action<$0> callback= + ($1) => { + m.Invoke(instance, new object[]{ $1 }); + }; + return callback; + } +".Replace("$0", g).Replace("$1", a); + + w.WriteLine(source); + + if (i > 4) w.WriteLine(@" +#endif +"); + } + + + w.WriteLine(@" + } +} +"); + } + + var path = UniGLTF.UnityPath.FromUnityPath(GENERATE_PATH); + File.WriteAllText(path.FullPath, sb.ToString().Replace("\r\n", "\n")); + path.ImportAsset(); + } +#endif + + #region no arguments + public static Action Create(MethodInfo m) + { + return (s) => + { + m.Invoke(s, new object[] { }); + }; + } + + public static Action CreateWithThis(MethodInfo m, S instance) + { + return () => + { + m.Invoke(instance, new object[] { }); + }; + } + #endregion + } +} diff --git a/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.cs.meta b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.cs.meta new file mode 100644 index 0000000000..7510665dfa --- /dev/null +++ b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b4bdb47bf29e1214a9e3da9b4ae9f31e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.g.cs b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.g.cs new file mode 100644 index 0000000000..2c55e18aec --- /dev/null +++ b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.g.cs @@ -0,0 +1,321 @@ + +using System; +using System.Reflection; + + +namespace UniJSON +{ + public static partial class GenericInvokeCallFactory + { + +//////////// Create + +#if UNITY_5 + public static Delegate Create(MethodInfo m) +#else + public static Action Create(MethodInfo m) +#endif + { + Action callback= + (s, a0) => + { + m.Invoke(s, new object[] { a0 }); + }; + return callback; + } + + +#if UNITY_5 + public static Delegate Create(MethodInfo m) +#else + public static Action Create(MethodInfo m) +#endif + { + Action callback= + (s, a0, a1) => + { + m.Invoke(s, new object[] { a0, a1 }); + }; + return callback; + } + + +#if UNITY_5 + public static Delegate Create(MethodInfo m) +#else + public static Action Create(MethodInfo m) +#endif + { + Action callback= + (s, a0, a1, a2) => + { + m.Invoke(s, new object[] { a0, a1, a2 }); + }; + return callback; + } + + +#if UNITY_5 +#else + + +#if UNITY_5 + public static Delegate Create(MethodInfo m) +#else + public static Action Create(MethodInfo m) +#endif + { + Action callback= + (s, a0, a1, a2, a3) => + { + m.Invoke(s, new object[] { a0, a1, a2, a3 }); + }; + return callback; + } + + +#endif + + +#if UNITY_5 +#else + + +#if UNITY_5 + public static Delegate Create(MethodInfo m) +#else + public static Action Create(MethodInfo m) +#endif + { + Action callback= + (s, a0, a1, a2, a3, a4) => + { + m.Invoke(s, new object[] { a0, a1, a2, a3, a4 }); + }; + return callback; + } + + +#endif + + +#if UNITY_5 +#else + + +#if UNITY_5 + public static Delegate Create(MethodInfo m) +#else + public static Action Create(MethodInfo m) +#endif + { + Action callback= + (s, a0, a1, a2, a3, a4, a5) => + { + m.Invoke(s, new object[] { a0, a1, a2, a3, a4, a5 }); + }; + return callback; + } + + +#endif + +//////////// CreateWithThis + +#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(); + } + } + + // ToDo: CreateDelegate + Action callback= + (a0) => { + m.Invoke(instance, new object[]{ a0 }); + }; + return callback; + } + + +#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(); + } + } + + // ToDo: CreateDelegate + Action callback= + (a0, a1) => { + m.Invoke(instance, new object[]{ a0, a1 }); + }; + return callback; + } + + +#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(); + } + } + + // ToDo: CreateDelegate + Action callback= + (a0, a1, a2) => { + m.Invoke(instance, new object[]{ a0, a1, a2 }); + }; + return callback; + } + + +#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(); + } + } + + // ToDo: CreateDelegate + Action callback= + (a0, a1, a2, a3) => { + m.Invoke(instance, new object[]{ a0, a1, a2, a3 }); + }; + return callback; + } + + +#if UNITY_5 +#else + + +#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(); + } + } + + // ToDo: CreateDelegate + Action callback= + (a0, a1, a2, a3, a4) => { + m.Invoke(instance, new object[]{ a0, a1, a2, a3, a4 }); + }; + return callback; + } + + +#endif + + +#if UNITY_5 +#else + + +#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(); + } + } + + // ToDo: CreateDelegate + Action callback= + (a0, a1, a2, a3, a4, a5) => { + m.Invoke(instance, new object[]{ a0, a1, a2, a3, a4, a5 }); + }; + return callback; + } + + +#endif + + + } +} + diff --git a/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.g.cs.meta b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.g.cs.meta new file mode 100644 index 0000000000..5ce58d6105 --- /dev/null +++ b/Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.g.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 56dfdc21f4d594143ab023e6bd171f91 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UniJSON35/UniJSON/UniJSON.csproj b/UniJSON35/UniJSON/UniJSON.csproj index 4498ee504b..36586b8b0f 100644 --- a/UniJSON35/UniJSON/UniJSON.csproj +++ b/UniJSON35/UniJSON/UniJSON.csproj @@ -18,7 +18,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;UNITY_5 prompt 4 @@ -43,4 +43,4 @@ - + \ No newline at end of file