public static string VerifyName(string name, CheckNameType type) { if (string.IsNullOrEmpty(name)) { return(ReportError("name IsNullOrEmpty.", type)); } if (char.IsDigit(name[0])) { return(ReportError("name cannot begin with number.", type)); } switch (name) { case "bean": case "list": case "BeanDefine": //case "variable": return(ReportError(name + " is reserved", type)); } foreach (var c in name) { if (char.IsWhiteSpace(c) || char.IsSymbol(c) || char.IsPunctuation(c) || char.IsSeparator(c)) { return(ReportError("IsWhiteSpace IsSymbol IsPunctuation ...", type)); } } return(null); }
private static string ReportError(string msg, CheckNameType type) { switch (type) { case CheckNameType.ShowMsg: MessageBox.Show(msg); return(msg); case CheckNameType.ThrowExp: throw new Exception(msg); default: return(msg); } }