123456789101112131415161718192021222324252627282930313233343536373839 |
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- namespace InABox.WPF
- {
- public class IntegerCalculatorFunction : AbstractCalculatorFunction<int, NumericCalculatorType>
- {
-
- protected override int Calculate(int current, int next, NumericCalculatorType type)
- {
- var result = type switch
- {
- NumericCalculatorType.Sum => current + next,
- NumericCalculatorType.Product => current * next,
- NumericCalculatorType.Subtraction => current - next,
- NumericCalculatorType.Maximum => current > next ? current : next,
- NumericCalculatorType.Minimum => current < next ? current : next,
- _ => current
- };
- return result;
- }
- }
- public class IntegerArrayConverter : AbstractNumericArrayConverter<int>
- {
- protected override int[] Convert(IEnumerable<string> values)
- {
- var result = values.Select(int.Parse).ToArray();
- return result;
- }
- }
-
- public class IntegerCalculator : AbstractNumericCalculator<int, IntegerCalculatorFunction>
- {
- [TypeConverter(typeof(IntegerArrayConverter))]
- public override int[] Constants { get; set; }
- }
- }
|