示例#1
0
        private static void InitializingSwitch(object sender, InitializingSwitchEventArgs e)
        {
            Switch sw = e.Switch;

            // Ported from https://referencesource.microsoft.com/#System/compmod/system/diagnostics/Switch.cs,173
            SwitchElementsCollection switchSettings = DiagnosticsConfiguration.SwitchSettings;

            if (switchSettings != null)
            {
                SwitchElement mySettings = switchSettings[sw.DisplayName];

                if (mySettings != null)
                {
                    if (mySettings.Value != null)
                    {
                        sw.Value = mySettings.Value;
                    }
                    else
                    {
                        sw.Value = sw.DefaultValue;
                    }

                    TraceUtils.CopyStringDictionary(sw.Attributes, mySettings.Attributes);
                }
            }
        }
 public SwitchResult(SwitchElement element) : this(element?.Label)
 {
     if (element == null)
     {
         throw  new ArgumentNullException(nameof(element));
     }
     Value = element.On;
 }
示例#3
0
 public bool Equals(SwitchElement other)
 {
     if (ReferenceEquals(null, other))
         return false;
     if (ReferenceEquals(this, other))
         return true;
     return Equals(other.Key, Key) && other.Value.Equals(Value);
 }
        public static ElseElement Else(this SwitchElement me, string label)
        {
            var c = new ElseElement {
                Label = label
            };

            me?.Cases.Add(c);
            return(c);
        }
        public static CaseElement Case(this SwitchElement me, string label, string when)
        {
            var c = new CaseElement {
                Label = label, When = when
            };

            me?.Cases.Add(c);
            return(c);
        }
        public static SwitchElement Switch(this MessageElement me, string label, string on)
        {
            var sw = new SwitchElement {
                Label = label, On = on
            };

            me?.Fields.Add(sw);
            return(sw);
        }
示例#7
0
 public bool Equals(SwitchElement other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.Key, Key) && other.Value.Equals(Value));
 }
示例#8
0
        protected override void OnElementChanged(ElementChangedEventArgs <Switch> e)
        {
            if (e.OldElement != null)
            {
                e.OldElement.Toggled -= OnElementToggled;
            }

            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    var input = new SwitchElement();
                    SetNativeControl(input);
                    Control.Change += OnControlValueChanged;
                }

                Control.IsChecked     = Element.IsToggled;
                e.NewElement.Toggled += OnElementToggled;
            }

            base.OnElementChanged(e);
        }
示例#9
0
        public string Visit(SwitchElement switchElement)
        {
            var cases = switchElement.Cases.Values.Select(v => v.Accept(this));

            return(JoinAlternatives(cases));
        }
示例#10
0
 private void Awake()
 {
     switchElement = GetComponentInChildren <SwitchElement>();
     switchElement.OnValueChanged.AddListener(delegate { CallEventOnValueChanged(switchElement.isOn); });
 }
示例#11
0
        public IFormElement Render()
        {
            IFormElement element;

            switch (Type)
            {
            case FormElementType.Entry:
                element = new EntryElement();
                break;

            case FormElementType.Address:
                element = new AddressElement();
                break;

            case FormElementType.DatePicker:
                element = new DatePickerElement();
                break;

            case FormElementType.Picker:
                element = new PickerElement();
                break;

            case FormElementType.Editor:
                element = new EditorElement();
                break;

            case FormElementType.Switch:
                element = new SwitchElement();
                break;

            case FormElementType.CheckboxList:
                element = new CheckboxListElement();
                break;

            case FormElementType.Hidden:
                element = new HiddenElement();
                break;

            case FormElementType.Button:
                element = new ButtonElement();
                break;

            case FormElementType.Label:
                element = new LabelElement();
                break;

            default:
                element = new EntryElement();
                break;
            }
            element.Label         = this.Label;
            element.Key           = Key;
            element.Keyboard      = Keyboard;
            element.HeightRequest = HeightRequest;
            element.Options       = Options;
            element.Required      = Required;
            element.Attributes    = Attributes;
            element.AutoPostBack  = AutoPostBack;

            if (!string.IsNullOrWhiteSpace(ElementBackgroundColor))
            {
                element.ElementBackgroundColor = (Color) new ColorTypeConverter().ConvertFromInvariantString(ElementBackgroundColor);
            }

            if (!string.IsNullOrWhiteSpace(ElementTextColor))
            {
                element.ElementTextColor = (Color) new ColorTypeConverter().ConvertFromInvariantString(ElementTextColor);
            }

            element.Render();
            if (!string.IsNullOrWhiteSpace(Value))
            {
                element.Value = Value;
            }

            return(element);
        }