| | 1 | | using System.Text.RegularExpressions; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Errors; |
| | 3 | | using ValidateLib.Metadata.Descriptors; |
| | 4 | |
|
| | 5 | | namespace ValidateLib.TabularData.Datatypes |
| | 6 | | { |
| | 7 | | public class BaseDT : IComparable<BaseDT> |
| | 8 | | { |
| 1 | 9 | | public string stringValue { get; set; } |
| 1 | 10 | | public FormatDescriptor? format { get; set; } |
| | 11 | |
|
| 1 | 12 | | public BaseDT() |
| | 13 | | { |
| 1 | 14 | | stringValue = "Invalid"; |
| 1 | 15 | | } |
| 1 | 16 | | public BaseDT(string stringValue) |
| | 17 | | { |
| 1 | 18 | | this.stringValue = stringValue; |
| 1 | 19 | | } |
| | 20 | |
|
| 1 | 21 | | public BaseDT(string stringValue, FormatDescriptor format) |
| | 22 | | { |
| 1 | 23 | | this.stringValue = stringValue; |
| 1 | 24 | | this.format = format; |
| 1 | 25 | | } |
| | 26 | |
|
| | 27 | | protected void MatchRegex(string regexString, string stringValue) |
| | 28 | | { |
| | 29 | | try |
| | 30 | | { |
| 1 | 31 | | Regex regex = new Regex(regexString); |
| 1 | 32 | | if (!regex.IsMatch(stringValue)) |
| 1 | 33 | | ErrorFactory.ThrowDatatypeValidationError($"regex: {regexString} value: {stringValue}"); |
| 1 | 34 | | } |
| 0 | 35 | | catch (ArgumentException) |
| | 36 | | { |
| 0 | 37 | | ErrorFactory.ThrowDatatypeValidationError($"regex: {regexString} value: {stringValue}"); |
| 0 | 38 | | } |
| 1 | 39 | | } |
| | 40 | |
|
| | 41 | | protected void VerifyFormatPatternIsValidRegex(string formatPattern) |
| | 42 | | { |
| | 43 | | try |
| | 44 | | { |
| 0 | 45 | | Regex regex = new Regex(formatPattern); |
| 0 | 46 | | } |
| 0 | 47 | | catch (Exception) |
| | 48 | | { |
| 0 | 49 | | ErrorFactory.ThrowInvalidFormatError(formatPattern, formatPattern); |
| 0 | 50 | | } |
| 0 | 51 | | } |
| | 52 | |
|
| | 53 | | virtual public int CompareTo(BaseDT? other) |
| | 54 | | { |
| 0 | 55 | | throw new ArgumentException(); |
| | 56 | | } |
| | 57 | |
|
| | 58 | | virtual public bool IsPatternValid(FormatDescriptor format) |
| | 59 | | { |
| 0 | 60 | | throw new NotImplementedException(); |
| | 61 | | } |
| | 62 | | } |
| | 63 | | } |