From e6181c24124d97f2fbc932b8a68311e625463156 Mon Sep 17 00:00:00 2001 From: uzvkl Date: Tue, 11 Jun 2019 23:05:52 +0200 Subject: Move dsa related stuff to subfolder --- dsa/DSALib/Auxiliary/Calculator/Argument.cs | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 dsa/DSALib/Auxiliary/Calculator/Argument.cs (limited to 'dsa/DSALib/Auxiliary/Calculator/Argument.cs') diff --git a/dsa/DSALib/Auxiliary/Calculator/Argument.cs b/dsa/DSALib/Auxiliary/Calculator/Argument.cs new file mode 100644 index 0000000..e681377 --- /dev/null +++ b/dsa/DSALib/Auxiliary/Calculator/Argument.cs @@ -0,0 +1,35 @@ +using System; + +namespace DSALib.Auxiliary.Calculator +{ + /// + /// Provides an ISolvable class to save numbers. The class handles Argument checking and conversion from string to int. + /// + 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 -- cgit v1.2.3-54-g00ecf