-
Notifications
You must be signed in to change notification settings - Fork 2
/
Helpers.cs
28 lines (25 loc) · 964 Bytes
/
Helpers.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
using EnhancedPatternMatching.Models;
namespace EnhancedPatternMatching.LanguageExtensions
{
public static class Helpers
{
/// <summary>
/// Pattern matching
/// </summary>
public static bool IsLetterOrSeparator(this char character) =>
character is (>= 'a' and <= 'z') or (>= 'A' and <= 'Z')
or '.' or ',' and not ' ';
/// <summary>
/// Conventional
/// </summary>
public static bool IsLetterSeparator(this char character) =>
char.IsLetter(character) || char.IsSeparator(character) && !char.IsWhiteSpace(character);
public static string Greetings(this Visitor visitor) => visitor switch
{
{ Country: "USA" } => "Hello",
{ Country: "Germany" } => "hallo",
{ Country: "Mexico" } => "Hola",
_ => throw new ArgumentOutOfRangeException(nameof(visitor), visitor, null)
};
}
}