public static int GetClassID(Type type) { ClassIDAttribute attribute = type.GetCustomAttribute <ClassIDAttribute>(); if (attribute != null) { return(attribute.ClassID); } else { return(0); } }
static GameModuleFactory() { ICollection <Type> moduleClasses = AssemblyUtility.FindClasses(typeof(GameModule), true, false); entries = new Dictionary <int, ConstructorInfo>(moduleClasses.Count); foreach (Type item in moduleClasses) { ClassIDAttribute attribute = item.GetCustomAttribute <ClassIDAttribute>(); if (attribute != null) { Debug.Assert(entries.ContainsKey(attribute.ClassID) == false); entries.Add(attribute.ClassID, item.GetConstructor(Type.EmptyTypes)); } } }
public T FindChildByClass <T>() where T : GameModule { return((T)FindChildByClassID(ClassIDAttribute.GetClassID(typeof(T)))); }