diff options
author | Dennis Kobert <d-kobert@web.de> | 2019-05-19 17:58:42 +0200 |
---|---|---|
committer | Dennis Kobert <d-kobert@web.de> | 2019-05-19 17:58:42 +0200 |
commit | 2ab4051c6fe720dc47e99b0c305a0d779ee02d51 (patch) | |
tree | 9510ddbb174a54474934adf7991a5ba2aa39f818 /DSALib/Auxiliary/Calculator/Argument.cs | |
parent | c4d046858e0822b7c2c540ac2368b2c0e88e7a26 (diff) |
Moved Gamelogic to DSALib
Diffstat (limited to 'DSALib/Auxiliary/Calculator/Argument.cs')
-rw-r--r-- | DSALib/Auxiliary/Calculator/Argument.cs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/DSALib/Auxiliary/Calculator/Argument.cs b/DSALib/Auxiliary/Calculator/Argument.cs new file mode 100644 index 0000000..5ed9ee3 --- /dev/null +++ b/DSALib/Auxiliary/Calculator/Argument.cs @@ -0,0 +1,35 @@ +using System; + +namespace DSACore.Auxiliary.Calculator +{ + /// <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 var result)) + throw new ArgumentException($"Kann {value} nicht in Integer konvertieren"); + + this.value = result; + } + + public int Solve() + { + return value; + } + + public override string ToString() + { + return value.ToString(); + } + } +}
\ No newline at end of file |