using System; using System.Collections; using System.Collections.Generic; using System.Reflection; namespace ModestTree { public static class ReflectionUtil { public static Array CreateArray(Type elementType, List instances) { var array = Array.CreateInstance(elementType, instances.Count); for (int i = 0; i < instances.Count; i++) { var instance = instances[i]; if (instance != null) { Assert.That(instance.GetType().DerivesFromOrEqual(elementType), "Wrong type when creating array, expected something assignable from '"+ elementType +"', but found '" + instance.GetType() + "'"); } array.SetValue(instance, i); } return array; } public static IList CreateGenericList(Type elementType, List instances) { var genericType = typeof(List<>).MakeGenericType(elementType); var list = (IList)Activator.CreateInstance(genericType); for (int i = 0; i < instances.Count; i++) { var instance = instances[i]; if (instance != null) { Assert.That(instance.GetType().DerivesFromOrEqual(elementType), "Wrong type when creating generic list, expected something assignable from '"+ elementType +"', but found '" + instance.GetType() + "'"); } list.Add(instance); } return list; } public static string ToDebugString(this MethodInfo method) { return "{0}.{1}".Fmt(method.DeclaringType.PrettyName(), method.Name); } public static string ToDebugString(this Action action) { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return action.ToString(); #else return action.Method.ToDebugString(); #endif } public static string ToDebugString(this Action action) { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return action.ToString(); #else return action.Method.ToDebugString(); #endif } public static string ToDebugString(this Action action) { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return action.ToString(); #else return action.Method.ToDebugString(); #endif } public static string ToDebugString(this Action action) { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return action.ToString(); #else return action.Method.ToDebugString(); #endif } public static string ToDebugString(this Action action) { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return action.ToString(); #else return action.Method.ToDebugString(); #endif } public static string ToDebugString(this #if NET_4_6 Action action) #else ModestTree.Util.Action action) #endif { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return action.ToString(); #else return action.Method.ToDebugString(); #endif } public static string ToDebugString(this #if NET_4_6 Action action) #else ModestTree.Util.Action action) #endif { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return action.ToString(); #else return action.Method.ToDebugString(); #endif } public static string ToDebugString(this Func func) { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return func.ToString(); #else return func.Method.ToDebugString(); #endif } public static string ToDebugString(this Func func) { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return func.ToString(); #else return func.Method.ToDebugString(); #endif } public static string ToDebugString(this Func func) { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return func.ToString(); #else return func.Method.ToDebugString(); #endif } public static string ToDebugString(this Func func) { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR return func.ToString(); #else return func.Method.ToDebugString(); #endif } } }