extract method for reuse as extension

This commit is contained in:
Brendan Forster
2015-07-17 07:32:42 +09:30
parent b191ebc3cd
commit c93eeaaa40
2 changed files with 13 additions and 20 deletions
+11
View File
@@ -101,5 +101,16 @@ namespace Octokit
//We need to have the last word.
yield return new String(letters, wordStartIndex, letters.Length - wordStartIndex);
}
static Regex nameWithOwner = new Regex("[a-zA-Z.]{1,}/[a-zA-Z.]{1,}"
#if (!PORTABLE && !NETFX_CORE)
, RegexOptions.Compiled
#endif
);
internal static bool IsNameWithOwnerFormat(this string input)
{
return nameWithOwner.IsMatch(input);
}
}
}
+2 -20
View File
@@ -267,15 +267,10 @@ namespace Octokit
if (Repos.Any())
{
var invalidFormatRepos = Repos.Where(x => !IsNameWithOwnerFormat(x));
var invalidFormatRepos = Repos.Where(x => !x.IsNameWithOwnerFormat());
if (invalidFormatRepos.Any())
{
var parameterList = string.Join(", ", invalidFormatRepos);
var message = string.Format(
CultureInfo.InvariantCulture,
"The list of repositories must be formatted as 'owner/name' - these values don't match this rule: {0}",
parameterList);
throw new ArgumentException(message);
throw new RepositoryFormatException(invalidFormatRepos);
}
parameters.Add(
@@ -285,19 +280,6 @@ namespace Octokit
return new ReadOnlyCollection<string>(parameters);
}
// what rules do we define here?
static Regex nameWithOwner = new Regex("[a-zA-Z.]{1,}/[a-zA-Z.]{1,}"
#if (!PORTABLE && !NETFX_CORE)
, RegexOptions.Compiled
#endif
);
static bool IsNameWithOwnerFormat(string input)
{
return nameWithOwner.IsMatch(input);
}
internal string DebuggerDisplay
{
get