6 using System.Text.RegularExpressions;
8 namespace SiliconStudio.Core
15 private static readonly Regex MatchIdentifier =
new Regex(
"^[a-zA-Z_][a-zA-Z0-9_]*$");
25 return IsValidNamespace(text, out error);
36 if (text == null)
throw new ArgumentNullException(
"text");
38 if (
string.IsNullOrWhiteSpace(text))
40 error =
"Namespace cannot be empty";
44 var items = text.Split(
new[] {
'.' }, StringSplitOptions.None);
45 error = items.Where(
s => !IsIdentifier(s)).Select(item =>
string.Format(
"[{0}]", item, text)).FirstOrDefault();
58 if (text == null)
throw new ArgumentNullException(
"text");
59 return MatchIdentifier.Match(text).Success;
static bool IsValidNamespace(string text, out string error)
Determines whether the specified string is valid namespace identifier.
static bool IsIdentifier(string text)
Determines whether the specified text is a C# identifier.
Helper to verify naming conventions.
static bool IsValidNamespace(string text)
Determines whether the specified string is valid namespace identifier.