Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Results API #720

Closed
sys27 opened this issue Sep 12, 2023 · 0 comments · Fixed by #723
Closed

New Results API #720

sys27 opened this issue Sep 12, 2023 · 0 comments · Fixed by #723
Assignees
Milestone

Comments

@sys27
Copy link
Owner

sys27 commented Sep 12, 2023

API:

public abstract class Result
{
    public static implicit operator Result(NumberValue n) => new NumberResult(n);
    public static implicit operator NumberValue(NumberResult r) => r.Number;
    // ...

    public bool TryGetNumber(out NumberValue number);
    // ...

    public NumberValue Number => ...; // throw exception
    // ...

    public sealed class NumberResult : Result
    {
        public override string ToString() => ...;

        public NumberValue Number => ...;
    }
    
    public sealed class AngleResult : Result
    {
        public override string ToString() => ...;

        public AngleValue Angle => ...;
    }
    
    // ...
}

Usage:

// ...
var processor = new Processor();
var result = processor.Solve("1 + 2");
Console.WriteLine(result.Number);

// or 
var processor = new Processor();
var result = processor.Solve("1 + 2");
if (result.TryGetNumber(out var number))
    Console.WriteLine(number);

// or 
var processor = new Processor();
var result = processor.Solve("1 + 2");
if (result is NumberResult numberResult)
    Console.WriteLine(numberResult.Number);

// or 
var processor = new Processor();
var result = processor.Solve("1 + 2");
Console.WriteLine(result);
@sys27 sys27 added enhancement proposal Features that are not approved yet labels Sep 12, 2023
@sys27 sys27 added this to the Backlog milestone Sep 12, 2023
@sys27 sys27 self-assigned this Sep 12, 2023
@sys27 sys27 changed the title New API for results New Results API Sep 12, 2023
@sys27 sys27 removed the proposal Features that are not approved yet label Sep 12, 2023
@sys27 sys27 modified the milestones: Backlog, xFunc 4.4.0 Sep 12, 2023
sys27 added a commit that referenced this issue Sep 12, 2023
sys27 added a commit that referenced this issue Sep 12, 2023
sys27 added a commit that referenced this issue Sep 12, 2023
sys27 added a commit that referenced this issue Sep 12, 2023
sys27 added a commit that referenced this issue Sep 13, 2023
sys27 added a commit that referenced this issue Sep 13, 2023
sys27 added a commit that referenced this issue Sep 13, 2023
sys27 added a commit that referenced this issue Sep 13, 2023
sys27 added a commit that referenced this issue Sep 13, 2023
sys27 added a commit that referenced this issue Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant