| | | 1 | | using pva.SuperV.Engine.Exceptions; |
| | | 2 | | using System.Text.RegularExpressions; |
| | | 3 | | |
| | | 4 | | namespace pva.SuperV.Engine |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Validates an identifier so that t can be used as a C# namespace (project), class (class) or property (field). |
| | | 8 | | /// </summary> |
| | | 9 | | internal static partial class IdentifierValidation |
| | | 10 | | { |
| | | 11 | | /// <summary>Regex for validating identifier name.</summary> |
| | | 12 | | [GeneratedRegex(Constants.IdentifierNamePattern)] |
| | | 13 | | private static partial Regex IdentifierNameRegex(); |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Validates the identifier foe an entity. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="entityType">Type of entity.</param> |
| | | 19 | | /// <param name="identifier">Identifier to be validated.</param> |
| | | 20 | | /// <returns>Validated identifier.</returns> |
| | | 21 | | /// <exception cref="InvalidIdentifierNameException"></exception> |
| | | 22 | | public static string ValidateIdentifier(string entityType, string? identifier) |
| | 5283 | 23 | | { |
| | 5283 | 24 | | if (string.IsNullOrEmpty(identifier) || !IdentifierNameRegex().IsMatch(identifier)) |
| | 14 | 25 | | { |
| | 14 | 26 | | throw new InvalidIdentifierNameException(entityType, identifier, Constants.IdentifierNamePattern); |
| | | 27 | | } |
| | 5269 | 28 | | return identifier; |
| | 5269 | 29 | | } |
| | | 30 | | } |
| | | 31 | | } |