コード例 #1
0
        /// <summary>
        /// Updates the type conversion text when one of the types involved changes.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">Arguments describing the event.</param>
        private static void OnTypeConversionValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            DemoContentControl window = sender as DemoContentControl;

            if (sender != null)
            {
                window.UpdateTypeConversionText();
            }
        }
コード例 #2
0
        /// <summary>
        /// Updates the basic types text when the value in the basic types box changes.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">Arguments describing the event.</param>
        private static void OnBasicTypesValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            DemoContentControl window = sender as DemoContentControl;

            if (window != null)
            {
                string newValue = window.BasicTypesValue.Trim();

                if (newValue.Length == 0)
                {
                    window.UpdateBasicTypesText(null);
                }
                else if (stringRegex.IsMatch(newValue))
                {
                    window.UpdateBasicTypesText(SupportedTypes.String);
                }
                else if (newValue.ToUpperInvariant() == "TRUE")
                {
                    window.UpdateBasicTypesText(SupportedTypes.Boolean);
                }
                else if (charRegex.Match(newValue).Success)
                {
                    window.UpdateBasicTypesText(SupportedTypes.Character);
                }
                else if (newValue.ToUpperInvariant() == "FALSE")
                {
                    window.UpdateBasicTypesText(SupportedTypes.Boolean);
                }
                else if (intRegex.IsMatch(newValue))
                {
                    int   intValue;
                    uint  uintValue;
                    long  longValue;
                    ulong ulongValue;

                    if (int.TryParse(intNumbersRegex.Match(newValue).Value, out intValue))
                    {
                        window.UpdateBasicTypesText(SupportedTypes.Integer);
                    }
                    else if (uint.TryParse(intNumbersRegex.Match(newValue).Value, out uintValue))
                    {
                        window.UpdateBasicTypesText(SupportedTypes.UnsignedInteger);
                    }
                    else if (long.TryParse(intNumbersRegex.Match(newValue).Value, out longValue))
                    {
                        window.UpdateBasicTypesText(SupportedTypes.Long);
                    }
                    else if (ulong.TryParse(intNumbersRegex.Match(newValue).Value, out ulongValue))
                    {
                        window.UpdateBasicTypesText(SupportedTypes.UnsignedLong);
                    }
                    else
                    {
                        window.UpdateBasicTypesText(null);
                    }
                }
                else if (uintRegex.IsMatch(newValue))
                {
                    uint  uintValue;
                    ulong ulongValue;

                    if (uint.TryParse(intNumbersRegex.Match(newValue).Value, out uintValue))
                    {
                        window.UpdateBasicTypesText(SupportedTypes.UnsignedInteger);
                    }
                    else if (ulong.TryParse(intNumbersRegex.Match(newValue).Value, out ulongValue))
                    {
                        window.UpdateBasicTypesText(SupportedTypes.UnsignedLong);
                    }
                    else
                    {
                        window.UpdateBasicTypesText(null);
                    }
                }
                else if (longRegex.IsMatch(newValue))
                {
                    long  longValue;
                    ulong ulongValue;

                    if (long.TryParse(intNumbersRegex.Match(newValue).Value, out longValue))
                    {
                        window.UpdateBasicTypesText(SupportedTypes.Long);
                    }
                    else if (ulong.TryParse(intNumbersRegex.Match(newValue).Value, out ulongValue))
                    {
                        window.UpdateBasicTypesText(SupportedTypes.UnsignedLong);
                    }
                    else
                    {
                        window.UpdateBasicTypesText(null);
                    }
                }
                else if (ulongRegex.IsMatch(newValue))
                {
                    ulong ulongValue;

                    if (ulong.TryParse(intNumbersRegex.Match(newValue).Value, out ulongValue))
                    {
                        window.UpdateBasicTypesText(SupportedTypes.UnsignedLong);
                    }
                    else
                    {
                        window.UpdateBasicTypesText(null);
                    }
                }
                else if (floatRegex.IsMatch(newValue))
                {
                    window.UpdateBasicTypesText(SupportedTypes.SingleFloat);
                }
                else if (doubleRegex.IsMatch(newValue))
                {
                    window.UpdateBasicTypesText(SupportedTypes.DoubleFloat);
                }
                else if (decimalRegex.IsMatch(newValue))
                {
                    window.UpdateBasicTypesText(SupportedTypes.DecimalFloat);
                }
                else
                {
                    window.UpdateBasicTypesText(null);
                }
            }
        }