Exemplo n.º 1
0
        private void InitializeHelper()
        {
            Type configurableType = MayhemEntry.Instance.ConfigurableType;

            Type[] interfaceTypes = GetType().GetInterfaces();
            foreach (Type interfaceType in interfaceTypes)
            {
                if (interfaceType.Equals(configurableType))
                {
                    HasConfig = true;
                    break;
                }
            }

            object[] attList = GetType().GetCustomAttributes(typeof(MayhemModuleAttribute), true);
            if (attList.Length > 0)
            {
                MayhemModuleAttribute att = attList[0] as MayhemModuleAttribute;
                Name        = att.Name;
                Description = att.Name;
            }
        }
Exemplo n.º 2
0
        internal void TryAdd(Assembly assembly)
        {
            try
            {
                if (assembly != null)
                {
                    // Go through all the public classes in the assembly
                    foreach (Type type in assembly.GetExportedTypes())
                    {
                        // If it's parent class is the type we want
                        // and it implements the correct moduleType
                        if (type.IsSubclassOf(typeof(T)) && !type.IsAbstract)
                        {
                            object[] attList = type.GetCustomAttributes(typeof(MayhemModuleAttribute), true);
                            if (attList.Length > 0)
                            {
                                MayhemModuleAttribute att = attList[0] as MayhemModuleAttribute;

                                // Add it to our final list
                                Add(new ModuleType(type, att.Name, att.Description));
                            }
                            else
                            {
                                // TODO: Do something to tell the developer the module has an error
                                // throw new Exception("Module does not have MayhemModuleAttribute attribute set:\n" + type.FullName);
                            }
                        }

                        allTypes.Add(type);
                    }
                }
            }
            catch
            {
                // Swallow
            }
        }