Animatroller.Simulator.SimulatorForm.AutoWireUsingReflection_Simple C# (CSharp) Method

AutoWireUsingReflection_Simple() public method

public AutoWireUsingReflection_Simple ( IScene scene ) : SimulatorForm
scene IScene
return SimulatorForm
        public SimulatorForm AutoWireUsingReflection_Simple(IScene scene, params IRunningDevice[] excludeDevices)
        {
            var fields = scene.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            foreach (var field in fields)
            {
                object fieldValue = field.GetValue(scene);
                if (fieldValue == null)
                    continue;

                // Auto-wire
                if (typeof(IRunningDevice).IsInstanceOfType(fieldValue))
                {
                    if (excludeDevices.Contains((IRunningDevice)fieldValue))
                        // Excluded
                        continue;
                }

                else if (field.FieldType.Name.StartsWith("EnumStateMachine") ||
                    field.FieldType.Name.StartsWith("IntStateMachine"))
                {
                    var stateMachine = (Animatroller.Framework.Controller.IStateMachine)fieldValue;

                    var control = AddLabel(stateMachine.Name);
                    if (string.IsNullOrEmpty(stateMachine.CurrentStateString))
                        control.Text = "<idle>";
                    else
                        control.Text = stateMachine.CurrentStateString;

                    stateMachine.StateChangedString += (sender, e) =>
                    {
                        if (PendingClose)
                            return;

                        this.UIThread(delegate
                        {
                            if (string.IsNullOrEmpty(e.NewState))
                                control.Text = "<idle>";
                            else
                                control.Text = e.NewState;
                        });
                    };
                }
                //FIXME
                //else if (field.FieldType == typeof(Animatroller.Framework.Controller.CueList))
                //{
                //    var cueList = (Animatroller.Framework.Controller.CueList)fieldValue;

                //    var control = AddLabel(cueList.Name);

                //    cueList.CurrentCueId.Subscribe(x =>
                //        {
                //            this.UIThread(delegate
                //            {
                //                if (x.HasValue)
                //                    control.Text = x.ToString();
                //                else
                //                    control.Text = "<idle>";
                //            });
                //        });
                //}
            }

            return this;
        }