INNER CODE UNIT · C#

Switch

Blecki/dwarfcorp · DwarfCorp/Debugger.cs:40

        public class Switch
        {
            public String Name;
            public Action<bool> Set;
            public bool State;
        }

        public static IEnumerable<Switch> EnumerateSwitches()
        {
            foreach (var member in typeof(Switches).GetFields(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static))
            {
                global::System.Diagnostics.Debug.Assert(member.FieldType == typeof(bool));
                yield return new Switch
                {
                    Name = member.Name,
                    Set = (value) => member.SetValue(null, value),
                    State = (member.GetValue(null) as bool?).Value
                };

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…