forked from BornToBeRoot/NETworkManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaudValidator.cs
More file actions
31 lines (27 loc) · 1.07 KB
/
Copy pathBaudValidator.cs
File metadata and controls
31 lines (27 loc) · 1.07 KB
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
30
31
using System.Globalization;
using System.Linq;
using System.Windows.Controls;
using NETworkManager.Localization.Resources;
namespace NETworkManager.Validators;
public class BaudValidator : ValidationRule
{
/// <summary>
/// Possible baud rates.
/// </summary>
private readonly int[] _bauds =
{ 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 128000, 256000, 512000, 921600 };
/// <summary>
/// Check if the int is a valid baud rate.
/// </summary>
/// <param name="value">Baud like 9600.</param>
/// <param name="cultureInfo">Culture to use for validation.</param>
/// <returns>True if the value is a valid baut rate.</returns>
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (!int.TryParse(value as string, out var baud))
return new ValidationResult(false, Strings.EnterValidBaud);
return _bauds.Contains(baud)
? ValidationResult.ValidResult
: new ValidationResult(false, Strings.EnterValidBaud);
}
}