public void registerCreator(Type type, creator.ICanCreate creator, bool replace) { if (!this.isCreating(type) || replace) { this.creators[type] = creator; } }
static Creator() { Type type = typeof(valueType); MethodInfo method = MethodCache.GetMethod(type); if (method != null) { defaultCreator = (Func <valueType>)Delegate.CreateDelegate(typeof(Func <valueType>), method); return; } if ((method = MethodCache.GetConfigMethod(type)) != null) { configCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), method); configNullCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.GetConfigNullMethod(type)); return; } if (type.IsArray) { if (type.GetArrayRank() == 1) { Type elementType = type.GetElementType(); configNullCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateArrayNullMethod.MakeGenericMethod(elementType)); configCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateArrayMethod.MakeGenericMethod(elementType)); } return; } if (type.IsEnum) { Type enumType = System.Enum.GetUnderlyingType(type); if (enumType == typeof(uint)) { defaultCreator = enumUInt; } else if (enumType == typeof(byte)) { defaultCreator = enumByte; } else if (enumType == typeof(ulong)) { defaultCreator = enumULong; } else if (enumType == typeof(ushort)) { defaultCreator = enumUShort; } else if (enumType == typeof(long)) { defaultCreator = enumLong; } else if (enumType == typeof(short)) { defaultCreator = enumShort; } else if (enumType == typeof(sbyte)) { defaultCreator = enumSByte; } else { defaultCreator = enumInt; } return; } if (type.IsGenericType) { Type genericType = type.GetGenericTypeDefinition(); if (genericType == typeof(Nullable <>)) { configNullCreator = configCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateNullableMethod.MakeGenericMethod(type.GetGenericArguments())); return; } if (genericType == typeof(LeftArray <>)) { configNullCreator = configCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateLeftArrayMethod.MakeGenericMethod(type.GetGenericArguments())); return; } if (genericType == typeof(ListArray <>)) { Type[] parameterTypes = type.GetGenericArguments(); configNullCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateListArrayNullMethod.MakeGenericMethod(parameterTypes)); configCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateListArrayMethod.MakeGenericMethod(parameterTypes)); return; } if (genericType == typeof(List <>)) { Type[] parameterTypes = type.GetGenericArguments(); configNullCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateListNullMethod.MakeGenericMethod(parameterTypes)); configCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateListMethod.MakeGenericMethod(parameterTypes)); return; } #if DOTNET2 if (genericType == typeof(Queue <>) || genericType == typeof(Stack <>) || genericType == typeof(LinkedList <>)) #else if (genericType == typeof(HashSet <>) || genericType == typeof(Queue <>) || genericType == typeof(Stack <>) || genericType == typeof(SortedSet <>) || genericType == typeof(LinkedList <>)) #endif { Type[] parameterTypes = new Type[] { type, type.GetGenericArguments()[0] }; configNullCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateEnumerableConstructorNullMethod.MakeGenericMethod(parameterTypes)); configCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateEnumerableConstructorMethod.MakeGenericMethod(parameterTypes)); return; } if (genericType == typeof(Dictionary <,>)) { Type[] parameterTypes = type.GetGenericArguments(); configNullCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateDictionaryNullMethod.MakeGenericMethod(parameterTypes)); configCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateDictionaryMethod.MakeGenericMethod(parameterTypes)); return; } if (genericType == typeof(SortedDictionary <,>)) { Type[] parameterTypes = type.GetGenericArguments(); configNullCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateSortedDictionaryNullMethod.MakeGenericMethod(parameterTypes)); configCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateSortedDictionaryMethod.MakeGenericMethod(parameterTypes)); return; } if (genericType == typeof(SortedList <,>)) { Type[] parameterTypes = type.GetGenericArguments(); configNullCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateSortedListNullMethod.MakeGenericMethod(parameterTypes)); configCreator = (Func <Config, valueType>)Delegate.CreateDelegate(typeof(Func <Config, valueType>), MethodCache.CreateSortedListMethod.MakeGenericMethod(parameterTypes)); return; } } if (type.IsPointer || type.IsInterface) { return; } isValueType = type.IsValueType; #if NOJIT MemberCreator = new memberRandom().Random(); #else MemberDynamicMethod dynamicMethod = new MemberDynamicMethod(type); foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))// | BindingFlags.DeclaredOnly { dynamicMethod.Push(field); } dynamicMethod.Base(); try { MemberCreator = (creator)dynamicMethod.Create <creator>(); } catch (Exception error) { Console.WriteLine(error.ToString()); } #endif }
void Start() { i = 0; spawnB = GameObject.Find("spawnB").GetComponent<creator>(); spawnE= GameObject.Find("spawnE").GetComponent<creator>(); spawnA = GameObject.Find("spawnA").GetComponent<creator>(); spawnD= GameObject.Find("spawnD").GetComponent<creator>(); spawnG= GameObject.Find("spawnG").GetComponent<creator>(); firstrun = true; loopcounter= 0; }
public glas(creator angel) { this.angel = angel; }
public void registerCreator(Type type, creator.ICanCreate creator) { this.creators[type] = creator; }
public Singleton(Func <T> creator) => Instance = _singletons.GetOrAdd(_functions.GetOrAdd(creator, creator.GetMethodInfo().GetILBytes()), key => creator());