diff options
author | TrueDoctor <d-kobert@web.de> | 2018-07-17 21:18:59 +0200 |
---|---|---|
committer | TrueDoctor <d-kobert@web.de> | 2018-07-17 21:18:59 +0200 |
commit | 497a9eded3b785f7f96732c447943cc8bbad284b (patch) | |
tree | 87e40525b6d5173171597a0c8c288fd8d8e7f610 /DiscoBot/Auxiliary/Calculator/Argument.cs | |
parent | 496c9c32cb8d0d067e675855289904a22b05d9ac (diff) |
Added object oriented dice resolving
Diffstat (limited to 'DiscoBot/Auxiliary/Calculator/Argument.cs')
-rw-r--r-- | DiscoBot/Auxiliary/Calculator/Argument.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/DiscoBot/Auxiliary/Calculator/Argument.cs b/DiscoBot/Auxiliary/Calculator/Argument.cs new file mode 100644 index 0000000..2379bfe --- /dev/null +++ b/DiscoBot/Auxiliary/Calculator/Argument.cs @@ -0,0 +1,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(); + } + } +}
\ No newline at end of file |