/// <summary> /// Throws a DslSyntaxException if the argument is not a valid identifier. /// </summary> public static string ValidateIdentifier(string name, IConceptInfo errorContext, string additionalErrorMessage = null) { string error = CsUtility.GetIdentifierError(name); if (error != null) { if (!string.IsNullOrEmpty(additionalErrorMessage)) { error = additionalErrorMessage + " " + error; } throw new DslSyntaxException(errorContext, error); } return(name); }
public void ValidateNameTest() { string[] validNames = new[] { "abc", "ABC", "i", "a12300", "a1a", "_abc", "_123", "_", "a_a_" }; string[] invalidNames = new[] { "0", "2asdasd", "123", "1_", null, "", " abc", "abc ", " ", "!", "@", "#", "a!", "a@", "a#", "ač", "č", }; foreach (string name in validNames) { Console.WriteLine("Testing valid name '" + name + "'."); string error = CsUtility.GetIdentifierError(name); Console.WriteLine("Error: " + error); Assert.IsNull(error); } foreach (string name in invalidNames) { Console.WriteLine("Testing invalid name '" + name + "'."); string error = CsUtility.GetIdentifierError(name); Console.WriteLine("Error: " + error); if (name == null) { TestUtility.AssertContains(error, "null"); } else if (name == "") { TestUtility.AssertContains(error, "empty"); } else if (name == "") { TestUtility.AssertContains(error, new[] { name, "not valid" }); } } }
public string GetErrorMessageMethodName() { string filterName = null; if (FilterType.StartsWith(Source.Module.Name + ".")) { string dataStructureName = FilterType.Substring(Source.Module.Name.Length + 1); if (CsUtility.GetIdentifierError(dataStructureName) == null) { filterName = dataStructureName; } } if (filterName == null) { filterName = CsUtility.TextToIdentifier(FilterType); } return("GetErrorMessage_" + filterName); }