Beispiel #1
0
        public static void LoadScriptConfig(object script)
        {
            ScriptOptionContainer opts = ScriptInterface.Instance.Config = new ScriptOptionContainer();
            Type      t                = script.GetType();
            FieldInfo storageField     = t.GetField("OptionsStorage");
            FieldInfo optsField        = t.GetField("Options");
            FieldInfo dontPreconfField = t.GetField("DontPreconfigure");

            if (optsField != null)
            {
                opts.Options.AddRange((List <IOption>)optsField.GetValue(script));
            }
            if (storageField != null)
            {
                opts.Storage = (string)storageField.GetValue(script);
            }
            if (dontPreconfField != null)
            {
                _configured[opts.Storage] = (bool)dontPreconfField.GetValue(script);
            }
            else if (optsField != null)
            {
                _configured[opts.Storage] = false;
            }
            opts.SetDefaults();
            opts.Load();
        }
Beispiel #2
0
        public static void LoadScriptConfig(object script)
        {
            ScriptOptionContainer opts = ScriptInterface.Instance.Config = new ScriptOptionContainer();
            Type      t                = script.GetType();
            FieldInfo storageField     = t.GetField("OptionsStorage");
            FieldInfo optsField        = t.GetField("Options");
            FieldInfo multiOptsField   = t.GetField("MultiOptions");
            FieldInfo dontPreconfField = t.GetField("DontPreconfigure");

            if (multiOptsField != null)
            {
                List <FieldInfo> multiOpts = new List <FieldInfo>();
                foreach (string optField in (string[])multiOptsField.GetValue(script))
                {
                    FieldInfo fi = t.GetField(optField);
                    if (fi != null)
                    {
                        multiOpts.Add(fi);
                    }
                }
                foreach (FieldInfo opt in multiOpts)
                {
                    List <IOption> parsedOpt = (List <IOption>)opt.GetValue(script);
                    parsedOpt.ForEach(o => o.Category = opt.Name);
                    opts.MultipleOptions.Add(opt.Name, parsedOpt);
                }
            }
            if (optsField != null)
            {
                opts.Options.AddRange((List <IOption>)optsField.GetValue(script));
            }
            if (storageField != null)
            {
                opts.Storage = (string)storageField.GetValue(script);
            }
            if (dontPreconfField != null)
            {
                _configured[opts.Storage] = (bool)dontPreconfField.GetValue(script);
            }
            else if (optsField != null)
            {
                _configured[opts.Storage] = false;
            }
            opts.SetDefaults();
            opts.Load();
        }