Пример #1
0
        private static Dictionary <string, KeyCode> GetDictionaryOfControls(GameOptions gameOptions)
        {
            var properties = gameOptions.GetType().GetProperties();
            var controls   = properties.Where(prop => prop.PropertyType == typeof(KeyCode));

            return(controls.ToDictionary(control => control.Name, control => (KeyCode)control.GetValue(gameOptions, null)));
        }
Пример #2
0
        //TODO: Can't you just use Object.clone() for this?
        /// <summary>
        /// Returns a copy of the provided options.
        /// </summary>
        /// <param name="original"></param>
        /// <returns></returns>
        public static GameOptions Copy(this GameOptions original)
        {
            var properties = original.GetType().GetProperties();

            var copy = new GameOptions();

            foreach (var property in properties)
            {
                property.SetValue(copy, property.GetValue(original, null), null);
            }

            return(copy);
        }