Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ShellTest
- {
- class ExitCommand : ShellDLL.Command
- {
- CalculatorShell calcShell;
- public ExitCommand(CalculatorShell calcShell) :base("exit")
- {
- this.calcShell = calcShell;
- }
- public override bool Execute(params string[] args)
- {
- if (args.Length != 0)
- {
- return false;
- }
- calcShell.Exit(0);
- return true;
- }
- }
- class PlusCommand : ShellDLL.Command
- {
- CalculatorShell calcShell;
- public PlusCommand(CalculatorShell calcShell) : base("+")
- {
- this.calcShell = calcShell;
- }
- public override bool Execute(params string[] args)
- {
- if (args.Length != 0)
- {
- return false;
- }
- double number;
- if (!double.TryParse(args[0], out number))
- {
- return false;
- }
- calcShell.Result += number;
- calcShell.Format(calcShell.ToString());
- return true;
- }
- }
- class CalculatorShell : ShellDLL.Shell
- {
- public double Result { get; set; }
- public override string ToString()
- {
- return string.Format($"{Result:F2}");
- }
- protected override void Init()
- {
- base.Init();
- Result = 0.0;
- Format($"{Result:F2}");
- }
- public CalculatorShell()
- {
- AddCommand(new ExitCommand(this));
- AddCommand(new PlusCommand(this));
- }
- }
- public class Program
- {
- public static void Main(string[] args)
- {
- ShellDLL.Shell sh = new CalculatorShell();
- sh.ReadEvalPrint();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement