Beispiel #1
0
        public MOWAP GenerateModMOWAPFromDll(string file, Type imowaModInnitType)
        {
            MOWAP    mowap       = new MOWAP();
            string   path        = DirectorySearchTools.GetFilePathInDirectory(file, modFolder);
            Assembly modAssembly = Assembly.LoadFrom(path);

            Type[] classesNoDll     = modAssembly.GetTypes();
            bool   gotAllTheModInfo = false;

            //Ir em cada classe
            foreach (Type classeDoDll in classesNoDll)
            {
                //Ir em cada método de cada classe
                foreach (MethodInfo mInfo in classeDoDll.GetMethods(BindingFlags.Static | BindingFlags.Public))
                {
                    //Ir em cada atributo de cada método
                    foreach (Attribute attr in Attribute.GetCustomAttributes(mInfo, imowaModInnitType))
                    {
                        int         modLoadingPlace = 0, modPriority = 0;
                        FieldInfo[] fields = attr.GetType().GetFields();

                        foreach (FieldInfo f in fields)
                        {
                            if (f.Name == "modLoadingPlace")
                            {
                                modLoadingPlace = (int)f.GetValue(attr);
                            }
                            else if (f.Name == "modPriority")
                            {
                                modPriority = (int)f.GetValue(attr);
                            }
                        }
                        mowap = new MOWAP()
                        {
                            ModInnitMethod  = mInfo,
                            ModLoadingPlace = modLoadingPlace,
                            ModPriority     = modPriority
                        };
                        gotAllTheModInfo = true;
                        break;
                    }
                    if (gotAllTheModInfo)
                    {
                        break;
                    }
                }
                if (gotAllTheModInfo)
                {
                    break;
                }
            }
            return(mowap);
        }
        public void AddMethodInfoFromPriority(MOWAP modMowap)
        {
            switch ((ModPriority)modMowap.ModPriority)
            {
            case ModPriority.High:
                HighPriority.Add(modMowap.ModInnitMethod);
                break;

            case ModPriority.Medium:
                MediumPriority.Add(modMowap.ModInnitMethod);
                break;

            case ModPriority.Low:
                LowPriority.Add(modMowap.ModInnitMethod);
                break;

            default:
                break;
            }
        }