Example #1
0
        /// <summary>Get the settings for a machine, creating a new entry if missing.</summary>
        /// <param name="id">The unique machine ID.</param>
        public ModConfigMachine GetOrAddMachineOverrides(string id)
        {
            ModConfigMachine config = this.GetMachineOverrides(id);

            if (config == null)
            {
                this.MachineOverrides[id] = config = new ModConfigMachine();
            }

            return(config);
        }
Example #2
0
        /*********
        ** Public methods
        *********/
        /// <summary>Get the machine settings which don't match the default.</summary>
        public IDictionary <string, string> GetCustomSettings()
        {
            IDictionary <string, string> customSettings = new Dictionary <string, string>();

            var defaults = new ModConfigMachine();

            foreach (var property in this.GetType().GetProperties())
            {
                object curValue     = property.GetValue(this);
                object defaultValue = property.GetValue(defaults);

                if (!curValue.Equals(defaultValue))
                {
                    customSettings[property.Name] = curValue?.ToString();
                }
            }

            return(customSettings);
        }
Example #3
0
        /*********
        ** Public methods
        *********/
        /// <summary>Get the machine settings which don't match the default.</summary>
        public IDictionary <string, string?> GetCustomSettings()
        {
            Dictionary <string, string?> customSettings = new();

            var defaults = new ModConfigMachine();

            foreach (PropertyInfo property in this.GetType().GetProperties())
            {
                object?curValue     = property.GetValue(this);
                object?defaultValue = property.GetValue(defaults);

                bool equal = defaultValue?.Equals(curValue) ?? curValue is null;
                if (!equal)
                {
                    customSettings[property.Name] = curValue?.ToString();
                }
            }

            return(customSettings);
        }