зеркало из https://github.com/github/VisualStudio.git
Add a guard against empty strings
This commit is contained in:
Родитель
115d2f95fa
Коммит
14cd6e9ae7
|
@ -18,10 +18,8 @@ namespace GitHub.Authentication.CredentialManagement
|
|||
public CredentialSet(string target)
|
||||
: this()
|
||||
{
|
||||
if (string.IsNullOrEmpty(target))
|
||||
{
|
||||
throw new ArgumentNullException("target");
|
||||
}
|
||||
Guard.ArgumentNotEmptyString(target, "target");
|
||||
|
||||
Target = target;
|
||||
}
|
||||
|
||||
|
@ -102,7 +100,5 @@ namespace GitHub.Authentication.CredentialManagement
|
|||
// Clean up memory to the Enumeration pointer
|
||||
NativeMethods.CredFree(pCredentials);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -78,6 +78,7 @@
|
|||
<Link>Key.snk</Link>
|
||||
</None>
|
||||
<Compile Include="Helpers\ExceptionHelper.cs" />
|
||||
<Compile Include="Helpers\Guard.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="..\..\script\SolutionInfo.cs">
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Splat;
|
||||
|
||||
namespace GitHub
|
||||
{
|
||||
public static class Guard
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates that the string is not empty.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public static void ArgumentNotEmptyString(string value, string name)
|
||||
{
|
||||
// We already know the value is not null because of NullGuard.Fody.
|
||||
if (!string.IsNullOrWhiteSpace(value)) return;
|
||||
|
||||
string message = string.Format(CultureInfo.InvariantCulture, "The value for '{0}' must not be empty", name);
|
||||
#if DEBUG
|
||||
if (!ModeDetector.InUnitTestRunner())
|
||||
{
|
||||
Debug.Fail(message);
|
||||
}
|
||||
#endif
|
||||
throw new ArgumentException("String cannot be empty", name);
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
internal sealed class ValidatedNotNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче