Require CookieBuilder.Name to be a not null or empty

This commit is contained in:
Nate McMaster 2017-06-30 09:20:13 -07:00
parent 271faf11bb
commit 199b0fa212
3 changed files with 57 additions and 55 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Http.Abstractions;
namespace Microsoft.AspNetCore.Http
{
@ -10,10 +11,18 @@ namespace Microsoft.AspNetCore.Http
/// </summary>
public class CookieBuilder
{
private string _name;
/// <summary>
/// The name of the cookie.
/// </summary>
public virtual string Name { get; set; }
public virtual string Name
{
get => _name;
set => _name = !string.IsNullOrEmpty(value)
? value
: throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(value));
}
/// <summary>
/// The cookie path.

View File

@ -15,193 +15,183 @@ namespace Microsoft.AspNetCore.Http.Abstractions
/// </summary>
internal static string Exception_UseMiddlewareIServiceProviderNotAvailable
{
get { return GetString("Exception_UseMiddlewareIServiceProviderNotAvailable"); }
get => GetString("Exception_UseMiddlewareIServiceProviderNotAvailable");
}
/// <summary>
/// '{0}' is not available.
/// </summary>
internal static string FormatException_UseMiddlewareIServiceProviderNotAvailable(object p0)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareIServiceProviderNotAvailable"), p0);
}
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareIServiceProviderNotAvailable"), p0);
/// <summary>
/// No public '{0}' method found.
/// No public '{0}' or '{1}' method found.
/// </summary>
internal static string Exception_UseMiddlewareNoInvokeMethod
{
get { return GetString("Exception_UseMiddlewareNoInvokeMethod"); }
get => GetString("Exception_UseMiddlewareNoInvokeMethod");
}
/// <summary>
/// No public '{0}' method found.
/// No public '{0}' or '{1}' method found.
/// </summary>
internal static string FormatException_UseMiddlewareNoInvokeMethod(object p0, object p1)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoInvokeMethod"), p0, p1);
}
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoInvokeMethod"), p0, p1);
/// <summary>
/// '{0}' does not return an object of type '{1}'.
/// '{0}' or '{1}' does not return an object of type '{2}'.
/// </summary>
internal static string Exception_UseMiddlewareNonTaskReturnType
{
get { return GetString("Exception_UseMiddlewareNonTaskReturnType"); }
get => GetString("Exception_UseMiddlewareNonTaskReturnType");
}
/// <summary>
/// '{0}' does not return an object of type '{1}'.
/// '{0}' or '{1}' does not return an object of type '{2}'.
/// </summary>
internal static string FormatException_UseMiddlewareNonTaskReturnType(object p0, object p1, object p2)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNonTaskReturnType"), p0, p1, p2);
}
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNonTaskReturnType"), p0, p1, p2);
/// <summary>
/// The '{0}' method's first argument must be of type '{1}'.
/// The '{0}' or '{1}' method's first argument must be of type '{2}'.
/// </summary>
internal static string Exception_UseMiddlewareNoParameters
{
get { return GetString("Exception_UseMiddlewareNoParameters"); }
get => GetString("Exception_UseMiddlewareNoParameters");
}
/// <summary>
/// The '{0}' method's first argument must be of type '{1}'.
/// The '{0}' or '{1}' method's first argument must be of type '{2}'.
/// </summary>
internal static string FormatException_UseMiddlewareNoParameters(object p0, object p1, object p2)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoParameters"), p0, p1, p2);
}
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoParameters"), p0, p1, p2);
/// <summary>
/// Multiple public '{0}' methods are available.
/// Multiple public '{0}' or '{1}' methods are available.
/// </summary>
internal static string Exception_UseMiddleMutlipleInvokes
{
get { return GetString("Exception_UseMiddleMutlipleInvokes"); }
get => GetString("Exception_UseMiddleMutlipleInvokes");
}
/// <summary>
/// Multiple public '{0}' methods are available.
/// Multiple public '{0}' or '{1}' methods are available.
/// </summary>
internal static string FormatException_UseMiddleMutlipleInvokes(object p0, object p1)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddleMutlipleInvokes"), p0, p1);
}
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddleMutlipleInvokes"), p0, p1);
/// <summary>
/// The path in '{0}' must start with '/'.
/// </summary>
internal static string Exception_PathMustStartWithSlash
{
get { return GetString("Exception_PathMustStartWithSlash"); }
get => GetString("Exception_PathMustStartWithSlash");
}
/// <summary>
/// The path in '{0}' must start with '/'.
/// </summary>
internal static string FormatException_PathMustStartWithSlash(object p0)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_PathMustStartWithSlash"), p0);
}
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_PathMustStartWithSlash"), p0);
/// <summary>
/// Unable to resolve service for type '{0}' while attempting to Invoke middleware '{1}'.
/// </summary>
internal static string Exception_InvokeMiddlewareNoService
{
get { return GetString("Exception_InvokeMiddlewareNoService"); }
get => GetString("Exception_InvokeMiddlewareNoService");
}
/// <summary>
/// Unable to resolve service for type '{0}' while attempting to Invoke middleware '{1}'.
/// </summary>
internal static string FormatException_InvokeMiddlewareNoService(object p0, object p1)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_InvokeMiddlewareNoService"), p0, p1);
}
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_InvokeMiddlewareNoService"), p0, p1);
/// <summary>
/// The '{0}' method must not have ref or out parameters.
/// </summary>
internal static string Exception_InvokeDoesNotSupportRefOrOutParams
{
get { return GetString("Exception_InvokeDoesNotSupportRefOrOutParams"); }
get => GetString("Exception_InvokeDoesNotSupportRefOrOutParams");
}
/// <summary>
/// The '{0}' method must not have ref or out parameters.
/// </summary>
internal static string FormatException_InvokeDoesNotSupportRefOrOutParams(object p0)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_InvokeDoesNotSupportRefOrOutParams"), p0);
}
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_InvokeDoesNotSupportRefOrOutParams"), p0);
/// <summary>
/// The value must be greater than zero.
/// </summary>
internal static string Exception_PortMustBeGreaterThanZero
{
get { return GetString("Exception_PortMustBeGreaterThanZero"); }
get => GetString("Exception_PortMustBeGreaterThanZero");
}
/// <summary>
/// The value must be greater than zero.
/// </summary>
internal static string FormatException_PortMustBeGreaterThanZero()
{
return GetString("Exception_PortMustBeGreaterThanZero");
}
=> GetString("Exception_PortMustBeGreaterThanZero");
/// <summary>
/// No service for type '{0}' has been registered.
/// </summary>
internal static string Exception_UseMiddlewareNoMiddlewareFactory
{
get { return GetString("Exception_UseMiddlewareNoMiddlewareFactory"); }
get => GetString("Exception_UseMiddlewareNoMiddlewareFactory");
}
/// <summary>
/// No service for type '{0}' has been registered.
/// </summary>
internal static string FormatException_UseMiddlewareNoMiddlewareFactory(object p0)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoMiddlewareFactory"), p0);
}
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoMiddlewareFactory"), p0);
/// <summary>
/// '{0}' failed to create middleware of type '{1}'.
/// </summary>
internal static string Exception_UseMiddlewareUnableToCreateMiddleware
{
get { return GetString("Exception_UseMiddlewareUnableToCreateMiddleware"); }
get => GetString("Exception_UseMiddlewareUnableToCreateMiddleware");
}
/// <summary>
/// '{0}' failed to create middleware of type '{1}'.
/// </summary>
internal static string FormatException_UseMiddlewareUnableToCreateMiddleware(object p0, object p1)
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareUnableToCreateMiddleware"), p0, p1);
}
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareUnableToCreateMiddleware"), p0, p1);
/// <summary>
/// Types that implement '{0}' do not support explicit arguments.
/// </summary>
internal static string Exception_UseMiddlewareExplicitArgumentsNotSupported
{
get { return GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported"); }
get => GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported");
}
/// <summary>
/// Types that implement '{0}' do not support explicit arguments.
/// </summary>
internal static string FormatException_UseMiddlewareExplicitArgumentsNotSupported(object p0)
=> string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported"), p0);
/// <summary>
/// Argument cannot be null or empty.
/// </summary>
internal static string ArgumentCannotBeNullOrEmpty
{
return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported"), p0);
get => GetString("ArgumentCannotBeNullOrEmpty");
}
/// <summary>
/// Argument cannot be null or empty.
/// </summary>
internal static string FormatArgumentCannotBeNullOrEmpty()
=> GetString("ArgumentCannotBeNullOrEmpty");
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);

View File

@ -153,4 +153,7 @@
<data name="Exception_UseMiddlewareExplicitArgumentsNotSupported" xml:space="preserve">
<value>Types that implement '{0}' do not support explicit arguments.</value>
</data>
<data name="ArgumentCannotBeNullOrEmpty" xml:space="preserve">
<value>Argument cannot be null or empty.</value>
</data>
</root>