summaryrefslogtreecommitdiff
path: root/DiscoBot/Auxiliary/Calculator/Argument.cs
blob: 2379bfef1ea17b4fcfab510d6aedb514bb6b2e8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
namespace DiscoBot.Auxiliary.Calculator
{
    using System;
    
    /// <summary>
    /// Provides an ISolvable class to save numbers. The class handles Argument checking and conversion from string to int. 
    /// </summary>
    public class Argument : ISolvable
    {
        private readonly int value;

        public Argument(string value)
        {
            // check whether the value given is an empty string
            if (string.IsNullOrEmpty(value)) 
            {
                throw new ArgumentException("Argument kann nicht mit einem leeren string instanziert werden. ", nameof(value));
            }

            if (!int.TryParse(value, out int result))
            {
                throw new ArgumentException($"Kann {value} nicht in Integer konvertieren");
            }

            this.value = result;
        }

        public int Solve()
        {
            return this.value;
        }

        public override string ToString()
        {
            return this.value.ToString();
        }
    }
}