forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidationHelpers.cs
More file actions
48 lines (42 loc) · 1.22 KB
/
ValidationHelpers.cs
File metadata and controls
48 lines (42 loc) · 1.22 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace JavaScriptEngineSwitcher.Core.Helpers
{
using System;
using System.Linq;
using System.Text.RegularExpressions;
/// <summary>
/// Validation helpers
/// </summary>
public static class ValidationHelpers
{
/// <summary>
/// List of supported types
/// </summary>
private static readonly Type[] _supportedTypes =
{
typeof(Undefined), typeof(Boolean), typeof(Int32), typeof(Double), typeof(String)
};
/// <summary>
/// Regular expression for working with JS-names
/// </summary>
private static readonly Regex _jsNameRegex = new Regex(@"^[A-Za-z_\$][0-9A-Za-z_\$]*$");
/// <summary>
/// Checks whether supports a .NET type
/// </summary>
/// <param name="type">.NET type</param>
/// <returns>Result of check (true - is supported; false - is not supported)</returns>
public static bool IsSupportedType(Type type)
{
bool result = _supportedTypes.Contains(type);
return result;
}
/// <summary>
/// Checks a format of the name
/// </summary>
/// <param name="name">The name</param>
/// <returns>Result of check (true - correct format; false - wrong format)</returns>
public static bool CheckNameFormat(string name)
{
return _jsNameRegex.IsMatch(name);
}
}
}