Skip to content

Commit

Permalink
validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Iknow6aint committed Jan 4, 2023
1 parent ba1dfc7 commit c716497
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ATMAPP
static void Main(string[] arrgs)
{
AppScreen.Welcome();
string cardNumber = Utility.GetUserInput("your Card number");
long cardNumber = Validator.Convert<long>("Your card number ");
Console.WriteLine($"your name is {cardNumber}");

Utility.PressEnterToContinue();
Expand Down
Empty file added TypeDescriptor.cs
Empty file.
38 changes: 38 additions & 0 deletions Validator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;

public static class Validator
{
public static T Convert<T>(string prompt)
{
bool valid = false;
string userInput;

while (!valid)
{
userInput = Utility.GetUserInput(prompt);

try
{
var converter = TypeDescriptor.GetConverter(typeof(T));
if (converter != null)
{
return (T)converter.ConvertFromString(userInput);
}
else
{
return default;
}
}
catch
{
Console.WriteLine("Invalid Input. Try again");
}
}
return default;
}
}
Binary file modified bin/Debug/net6.0/c#.dll
Binary file not shown.
Binary file modified bin/Debug/net6.0/c#.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/net6.0/c#.csproj.CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e9dd098962fb844da76e7050def142db1ae72c5e
fa7ed969837a56ed2de2c707dd406110e19f0359
Binary file modified obj/Debug/net6.0/c#.dll
Binary file not shown.
Binary file modified obj/Debug/net6.0/c#.pdb
Binary file not shown.
Binary file modified obj/Debug/net6.0/ref/c#.dll
Binary file not shown.
Binary file modified obj/Debug/net6.0/refint/c#.dll
Binary file not shown.

0 comments on commit c716497

Please sign in to comment.