コード例 #1
0
        public void loadConfiguration(Type configType)
        {
            bool flag = !Directory.Exists(Path.GetDirectoryName(this.configurationPath));

            if (flag)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(this.configurationPath));
            }
            bool flag2 = !File.Exists(this.configurationPath);

            if (flag2)
            {
                object obj   = Activator.CreateInstance(configType);
                bool   flag3 = !(obj is IMyConfig);
                if (flag3)
                {
                    throw new MyCoreException("configType is not part of a IMyConfig!", "MyConfig.cs");
                }
                IMyConfig myConfig = obj as IMyConfig;
                myConfig.SetupDefaults();
                this.configuration = myConfig;
                ((IMyConfig)this.configuration).setParent(this);
                this.save();
            }
            string json = File.ReadAllText(this.configurationPath);

            this.configuration = JsonUtility.FromJson(json, configType);
            ((IMyConfig)this.configuration).setParent(this);
        }
コード例 #2
0
        public void loadConfiguration(Type configType)
        {
            if (!File.Exists(this.configurationPath))
            {
                object obj = Activator.CreateInstance(configType);
                if (!(obj is IMyConfig))
                {
                    throw new MyCoreException("configType is not part of a IMyConfig!", "MyConfig.cs");
                }
                IMyConfig cfg = obj as IMyConfig;
                cfg.SetupDefaults();
                this.configuration = cfg;
                ((IMyConfig)this.configuration).setParent(this);
                this.save();
            }
            String json = File.ReadAllText(this.configurationPath);

            this.configuration = JsonUtility.FromJson(json, configType);
            ((IMyConfig)this.configuration).setParent(this);
        }