Пример #1
0
        public static int GetClassID(Type type)
        {
            ClassIDAttribute attribute = type.GetCustomAttribute <ClassIDAttribute>();

            if (attribute != null)
            {
                return(attribute.ClassID);
            }
            else
            {
                return(0);
            }
        }
Пример #2
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));
                }
            }
        }
Пример #3
0
 public T FindChildByClass <T>() where T : GameModule
 {
     return((T)FindChildByClassID(ClassIDAttribute.GetClassID(typeof(T))));
 }