diff --git a/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs b/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs index d2aa125f..bbb97f33 100644 --- a/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs +++ b/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs @@ -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 /// public class CookieBuilder { + private string _name; + /// /// The name of the cookie. /// - 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)); + } /// /// The cookie path. diff --git a/src/Microsoft.AspNetCore.Http.Abstractions/Properties/Resources.Designer.cs b/src/Microsoft.AspNetCore.Http.Abstractions/Properties/Resources.Designer.cs index 3b747cd4..0db61768 100644 --- a/src/Microsoft.AspNetCore.Http.Abstractions/Properties/Resources.Designer.cs +++ b/src/Microsoft.AspNetCore.Http.Abstractions/Properties/Resources.Designer.cs @@ -15,193 +15,183 @@ private static readonly ResourceManager _resourceManager /// internal static string Exception_UseMiddlewareIServiceProviderNotAvailable { - get { return GetString("Exception_UseMiddlewareIServiceProviderNotAvailable"); } + get => GetString("Exception_UseMiddlewareIServiceProviderNotAvailable"); } /// /// '{0}' is not available. /// internal static string FormatException_UseMiddlewareIServiceProviderNotAvailable(object p0) - { - return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareIServiceProviderNotAvailable"), p0); - } + => string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareIServiceProviderNotAvailable"), p0); /// - /// No public '{0}' method found. + /// No public '{0}' or '{1}' method found. /// internal static string Exception_UseMiddlewareNoInvokeMethod { - get { return GetString("Exception_UseMiddlewareNoInvokeMethod"); } + get => GetString("Exception_UseMiddlewareNoInvokeMethod"); } /// - /// No public '{0}' method found. + /// No public '{0}' or '{1}' method found. /// 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); /// - /// '{0}' does not return an object of type '{1}'. + /// '{0}' or '{1}' does not return an object of type '{2}'. /// internal static string Exception_UseMiddlewareNonTaskReturnType { - get { return GetString("Exception_UseMiddlewareNonTaskReturnType"); } + get => GetString("Exception_UseMiddlewareNonTaskReturnType"); } /// - /// '{0}' does not return an object of type '{1}'. + /// '{0}' or '{1}' does not return an object of type '{2}'. /// 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); /// - /// The '{0}' method's first argument must be of type '{1}'. + /// The '{0}' or '{1}' method's first argument must be of type '{2}'. /// internal static string Exception_UseMiddlewareNoParameters { - get { return GetString("Exception_UseMiddlewareNoParameters"); } + get => GetString("Exception_UseMiddlewareNoParameters"); } /// - /// The '{0}' method's first argument must be of type '{1}'. + /// The '{0}' or '{1}' method's first argument must be of type '{2}'. /// 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); /// - /// Multiple public '{0}' methods are available. + /// Multiple public '{0}' or '{1}' methods are available. /// internal static string Exception_UseMiddleMutlipleInvokes { - get { return GetString("Exception_UseMiddleMutlipleInvokes"); } + get => GetString("Exception_UseMiddleMutlipleInvokes"); } /// - /// Multiple public '{0}' methods are available. + /// Multiple public '{0}' or '{1}' methods are available. /// 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); /// /// The path in '{0}' must start with '/'. /// internal static string Exception_PathMustStartWithSlash { - get { return GetString("Exception_PathMustStartWithSlash"); } + get => GetString("Exception_PathMustStartWithSlash"); } /// /// The path in '{0}' must start with '/'. /// internal static string FormatException_PathMustStartWithSlash(object p0) - { - return string.Format(CultureInfo.CurrentCulture, GetString("Exception_PathMustStartWithSlash"), p0); - } + => string.Format(CultureInfo.CurrentCulture, GetString("Exception_PathMustStartWithSlash"), p0); /// /// Unable to resolve service for type '{0}' while attempting to Invoke middleware '{1}'. /// internal static string Exception_InvokeMiddlewareNoService { - get { return GetString("Exception_InvokeMiddlewareNoService"); } + get => GetString("Exception_InvokeMiddlewareNoService"); } /// /// Unable to resolve service for type '{0}' while attempting to Invoke middleware '{1}'. /// 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); /// /// The '{0}' method must not have ref or out parameters. /// internal static string Exception_InvokeDoesNotSupportRefOrOutParams { - get { return GetString("Exception_InvokeDoesNotSupportRefOrOutParams"); } + get => GetString("Exception_InvokeDoesNotSupportRefOrOutParams"); } /// /// The '{0}' method must not have ref or out parameters. /// internal static string FormatException_InvokeDoesNotSupportRefOrOutParams(object p0) - { - return string.Format(CultureInfo.CurrentCulture, GetString("Exception_InvokeDoesNotSupportRefOrOutParams"), p0); - } + => string.Format(CultureInfo.CurrentCulture, GetString("Exception_InvokeDoesNotSupportRefOrOutParams"), p0); /// /// The value must be greater than zero. /// internal static string Exception_PortMustBeGreaterThanZero { - get { return GetString("Exception_PortMustBeGreaterThanZero"); } + get => GetString("Exception_PortMustBeGreaterThanZero"); } /// /// The value must be greater than zero. /// internal static string FormatException_PortMustBeGreaterThanZero() - { - return GetString("Exception_PortMustBeGreaterThanZero"); - } + => GetString("Exception_PortMustBeGreaterThanZero"); /// /// No service for type '{0}' has been registered. /// internal static string Exception_UseMiddlewareNoMiddlewareFactory { - get { return GetString("Exception_UseMiddlewareNoMiddlewareFactory"); } + get => GetString("Exception_UseMiddlewareNoMiddlewareFactory"); } /// /// No service for type '{0}' has been registered. /// internal static string FormatException_UseMiddlewareNoMiddlewareFactory(object p0) - { - return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoMiddlewareFactory"), p0); - } + => string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareNoMiddlewareFactory"), p0); /// /// '{0}' failed to create middleware of type '{1}'. /// internal static string Exception_UseMiddlewareUnableToCreateMiddleware { - get { return GetString("Exception_UseMiddlewareUnableToCreateMiddleware"); } + get => GetString("Exception_UseMiddlewareUnableToCreateMiddleware"); } /// /// '{0}' failed to create middleware of type '{1}'. /// 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); /// /// Types that implement '{0}' do not support explicit arguments. /// internal static string Exception_UseMiddlewareExplicitArgumentsNotSupported { - get { return GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported"); } + get => GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported"); } /// /// Types that implement '{0}' do not support explicit arguments. /// internal static string FormatException_UseMiddlewareExplicitArgumentsNotSupported(object p0) + => string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported"), p0); + + /// + /// Argument cannot be null or empty. + /// + internal static string ArgumentCannotBeNullOrEmpty { - return string.Format(CultureInfo.CurrentCulture, GetString("Exception_UseMiddlewareExplicitArgumentsNotSupported"), p0); + get => GetString("ArgumentCannotBeNullOrEmpty"); } + /// + /// Argument cannot be null or empty. + /// + internal static string FormatArgumentCannotBeNullOrEmpty() + => GetString("ArgumentCannotBeNullOrEmpty"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/Microsoft.AspNetCore.Http.Abstractions/Resources.resx b/src/Microsoft.AspNetCore.Http.Abstractions/Resources.resx index 969b4044..176d3a80 100644 --- a/src/Microsoft.AspNetCore.Http.Abstractions/Resources.resx +++ b/src/Microsoft.AspNetCore.Http.Abstractions/Resources.resx @@ -153,4 +153,7 @@ Types that implement '{0}' do not support explicit arguments. + + Argument cannot be null or empty. + \ No newline at end of file