NanoXLSX.Core
3.0.0-rc.3
Loading...
Searching...
No Matches
Validators.cs
1
using
System.Text.RegularExpressions;
2
using
NanoXLSX.Exceptions
;
3
4
5
namespace
NanoXLSX.Utils
6
{
10
public
static
class
Validators
11
{
12
16
private
const
float
FLOAT_THRESHOLD = 0.0001f;
17
25
public
static
void
ValidateColor
(
string
hexCode,
bool
useAlpha,
bool
allowEmpty =
false
)
26
{
27
if
(
string
.IsNullOrEmpty(hexCode))
28
{
29
if
(allowEmpty)
30
{
31
return
;
32
}
33
throw
new
StyleException
(
"The color expression was null or empty"
);
34
}
35
36
int
length = useAlpha ? 8 : 6;
37
if
(hexCode.Length != length)
38
{
39
throw
new
StyleException
(
"The value '"
+ hexCode +
"' is invalid. A valid value must contain "
+ length +
" hex characters"
);
40
}
41
if
(!Regex.IsMatch(hexCode,
"[a-fA-F0-9]{6,8}"
))
42
{
43
throw
new
StyleException
(
"The expression '"
+ hexCode +
"' is not a valid hex value"
);
44
}
45
}
46
}
47
}
NanoXLSX.Exceptions.StyleException
Class for exceptions regarding Style incidents.
Definition
StyleException.cs:18
NanoXLSX.Utils.Validators
Class providing general validator methods.
Definition
Validators.cs:11
NanoXLSX.Utils.Validators.ValidateColor
static void ValidateColor(string hexCode, bool useAlpha, bool allowEmpty=false)
Validates the passed string, whether it is a valid RGB or ARGB value that can be used for Fills or Fo...
Definition
Validators.cs:25
NanoXLSX.Exceptions
Definition
FormatException.cs:12
NanoXLSX.Utils
Definition
Comparators.cs:6
Utils
Validators.cs
Generated by
1.15.0