Пример #1
0
        private void OnHandlerUnfocused(object sender, FocusEventArgs e)
        {
            decimal value = 0;

            if (decimal.TryParse(Text, out value))
            {
                if (MaximumAmount.IsNotNull() && value > MaximumAmount)
                {
                    Amount = MaximumAmount;
                    Text   = NumberType == EnumNumberType.Amount ? FormatterHelper.Format(Amount.Value) : FormatterHelper.FormatPercentage(Amount.Value);
                }
                else if (MinimumAmount.IsNotNull() && value < MinimumAmount)
                {
                    Amount = MinimumAmount;
                    Text   = NumberType == EnumNumberType.Amount ? FormatterHelper.Format(Amount.Value) : FormatterHelper.FormatPercentage(Amount.Value);
                }
                else
                {
                    Amount = value;
                    Text   = NumberType == EnumNumberType.Amount ? FormatterHelper.Format(Amount.Value) : FormatterHelper.FormatPercentage(Amount.Value);
                }
            }
            else
            {
                Text   = string.Empty;
                Amount = 0;
            }
        }
Пример #2
0
 public NumberEntry()
 {
     Text            = FormatterHelper.Format(0);
     Keyboard        = Keyboard.Numeric;
     this.Focused   += OnHandlerFocused;
     this.Unfocused += OnHandlerUnfocused;
 }
Пример #3
0
        protected override async Task FixAllAsync(
            Document document, ImmutableArray <Diagnostic> diagnostics, SyntaxEditor editor,
            CancellationToken cancellationToken)
        {
            var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            // Defer to our callback to actually make the edits for each diagnostic. In turn, it
            // will return 'true' if it made a multi-line conditional expression. In that case,
            // we'll need to explicitly format this node so we can get our special multi-line
            // formatting in VB and C#.
            var nestedEditor = new SyntaxEditor(root, document.Project.Solution.Workspace);

            foreach (var diagnostic in diagnostics)
            {
                await FixOneAsync(
                    document, diagnostic, nestedEditor, cancellationToken).ConfigureAwait(false);
            }

            var changedRoot = nestedEditor.GetChangedRoot();

            // Get the language specific rule for formatting this construct and call into the
            // formatted to explicitly format things.  Note: all we will format is the new
            // conditional expression as that's the only node that has the appropriate
            // annotation on it.
            var rules = new List <AbstractFormattingRule> {
                GetMultiLineFormattingRule()
            };

            var options = document.Project.AnalyzerOptions.GetAnalyzerOptionSet(root.SyntaxTree, cancellationToken);

#if CODE_STYLE
            var formattedRoot = FormatterHelper.Format(changedRoot,
                                                       GetSyntaxFormattingService(),
                                                       SpecializedFormattingAnnotation,
                                                       options,
                                                       rules, cancellationToken);
#else
            var formattedRoot = Formatter.Format(changedRoot,
                                                 SpecializedFormattingAnnotation,
                                                 document.Project.Solution.Workspace,
                                                 options,
                                                 rules, cancellationToken);
#endif
            changedRoot = formattedRoot;

            editor.ReplaceNode(root, changedRoot);
        }
Пример #4
0
 private void ChangeText()
 {
     Text = NumberType == EnumNumberType.Amount ? FormatterHelper.Format(Amount.Value) : FormatterHelper.FormatPercentage(Amount.Value);
 }
 private string FormatAmount(object value) => FormatterHelper.Format(System.Convert.ToDecimal(value));