-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcess.cs
29 lines (22 loc) · 1002 Bytes
/
Process.cs
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
using ParseDontValidate.Model;
namespace ParseDontValidate;
public static class Processor
{
private static readonly Random Random = new();
public static string Process(ICommand command) => command switch
{
TrimMessage a => TrimMessage(a),
GetCurrentTime a => GetCurrentTime(a),
GenerateRandomNumber a => GenerateRandomNumber(a),
_ => ReportUnknownCommand()
};
private static string TrimMessage(TrimMessage command) =>
command.Message.Length > command.MaxLength
? command.Message[..command.MaxLength] + "…"
: command.Message;
private static string GetCurrentTime(GetCurrentTime command) =>
$"The current time is {DateTime.Now.ToShortTimeString()}.";
private static string GenerateRandomNumber(GenerateRandomNumber command) =>
$"Your random number is {Random.Next(command.Min, command.Max)}.";
private static string ReportUnknownCommand() => "I don't know what to do now.";
}