1using System.Text.RegularExpressions;
21 string argbMessage = ValidateColorInternal(hexCode,
true, allowEmpty);
22 string rgbMessage =
null;
23 if ( argbMessage !=
null)
25 rgbMessage = ValidateColorInternal(hexCode,
false, allowEmpty);
26 if (rgbMessage !=
null)
40 public static void ValidateColor(
string hexCode,
bool useAlpha,
bool allowEmpty =
false)
42 string message = ValidateColorInternal(hexCode, useAlpha, allowEmpty);
56 private static string ValidateColorInternal(
string hexCode,
bool useAlpha,
bool allowEmpty)
58 if (
string.IsNullOrEmpty(hexCode))
64 return "The color expression cannot be null or empty";
67 int length = useAlpha ? 8 : 6;
68 if (hexCode.Length != length)
70 return "The value '" + hexCode +
"' is invalid. A valid value must contain " + length +
" hex characters";
72 if (!Regex.IsMatch(hexCode,
"[a-fA-F0-9]{6,8}"))
74 return "The expression '" + hexCode +
"' is not a valid hex value";
Class for exceptions regarding Style incidents.
Class providing general validator methods.
static void ValidateGenericColor(string hexCode, bool allowEmpty=false)
Validates the passed string, whether it is a valid RGB or ARGB value that can be used for Fills,...
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,...