Skip to content

How to create a formatter for math calculations #298

Answered by axunonb
Begounet asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, generally this can be done. However, by default formatting proceeds from left to right.
Before explaining a lot, here is a proof of concept in code.
(Btw: Putting the calculation method into the option part might reduce the number of required custom formatters.)

/// <summary>
/// A simplistic math formatter
/// </summary>
public class SimplisticMathFormatter : IFormatter
{
    /// <inheritdoc/>
    public string Name { get; set; } = "math";

    /// <inheritdoc/>
    public bool CanAutoDetect { get; set; } = false;

    /// <inheritdoc/>
    public bool TryEvaluateFormat(IFormattingInfo formattingInfo)
    {
        // + - * /
        var calculationType = formattingInfo.FormatterOpt…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@axunonb
Comment options

@Begounet
Comment options

@axunonb
Comment options

Answer selected by axunonb
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants