From 8f970d3d4844af2027518717c2b34438e0197b26 Mon Sep 17 00:00:00 2001 From: Chris R Date: Fri, 19 May 2017 12:55:55 -0700 Subject: [PATCH] React to StringSegment header parsers --- .../ProviderCultureResult.cs | 17 +++++----- .../RequestLocalizationMiddleware.cs | 11 ++++--- .../breakingchanges.netcore.json | 32 +++++++++++++++++++ 3 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Localization/breakingchanges.netcore.json diff --git a/src/Microsoft.AspNetCore.Localization/ProviderCultureResult.cs b/src/Microsoft.AspNetCore.Localization/ProviderCultureResult.cs index a8fa269ff3..2cb8b50e71 100644 --- a/src/Microsoft.AspNetCore.Localization/ProviderCultureResult.cs +++ b/src/Microsoft.AspNetCore.Localization/ProviderCultureResult.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.Collections.Generic; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Localization { @@ -15,8 +16,8 @@ namespace Microsoft.AspNetCore.Localization /// properties set to the same culture value. /// /// The name of the culture to be used for formatting, text, i.e. language. - public ProviderCultureResult(string culture) - : this(new List { culture }, new List { culture }) + public ProviderCultureResult(StringSegment culture) + : this(new List { culture }, new List { culture }) { } @@ -26,8 +27,8 @@ namespace Microsoft.AspNetCore.Localization /// /// The name of the culture to be used for formatting. /// The name of the ui culture to be used for text, i.e. language. - public ProviderCultureResult(string culture, string uiCulture) - : this(new List { culture }, new List { uiCulture }) + public ProviderCultureResult(StringSegment culture, StringSegment uiCulture) + : this(new List { culture }, new List { uiCulture }) { } @@ -36,7 +37,7 @@ namespace Microsoft.AspNetCore.Localization /// properties set to the same culture value. /// /// The list of cultures to be used for formatting, text, i.e. language. - public ProviderCultureResult(IList cultures) + public ProviderCultureResult(IList cultures) : this(cultures, cultures) { } @@ -47,7 +48,7 @@ namespace Microsoft.AspNetCore.Localization /// /// The list of cultures to be used for formatting. /// The list of ui cultures to be used for text, i.e. language. - public ProviderCultureResult(IList cultures, IList uiCultures) + public ProviderCultureResult(IList cultures, IList uiCultures) { Cultures = cultures; UICultures = uiCultures; @@ -56,11 +57,11 @@ namespace Microsoft.AspNetCore.Localization /// /// Gets the list of cultures to be used for formatting. /// - public IList Cultures { get; } + public IList Cultures { get; } /// /// Gets the list of ui cultures to be used for text, i.e. language; /// - public IList UICultures { get; } + public IList UICultures { get; } } } diff --git a/src/Microsoft.AspNetCore.Localization/RequestLocalizationMiddleware.cs b/src/Microsoft.AspNetCore.Localization/RequestLocalizationMiddleware.cs index 0e34da2231..01cef8c4e3 100644 --- a/src/Microsoft.AspNetCore.Localization/RequestLocalizationMiddleware.cs +++ b/src/Microsoft.AspNetCore.Localization/RequestLocalizationMiddleware.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; +using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Localization { @@ -131,7 +132,7 @@ namespace Microsoft.AspNetCore.Localization } private static CultureInfo GetCultureInfo( - IList cultureNames, + IList cultureNames, IList supportedCultures, bool fallbackToParentCultures) { @@ -152,7 +153,7 @@ namespace Microsoft.AspNetCore.Localization return null; } - private static CultureInfo GetCultureInfo(string name, IList supportedCultures) + private static CultureInfo GetCultureInfo(StringSegment name, IList supportedCultures) { // Allow only known culture names as this API is called with input from users (HTTP requests) and // creating CultureInfo objects is expensive and we don't want it to throw either. @@ -161,7 +162,7 @@ namespace Microsoft.AspNetCore.Localization return null; } var culture = supportedCultures.FirstOrDefault( - supportedCulture => string.Equals(supportedCulture.Name, name, StringComparison.OrdinalIgnoreCase)); + supportedCulture => StringSegment.Equals(supportedCulture.Name, name, StringComparison.OrdinalIgnoreCase)); if (culture == null) { @@ -172,7 +173,7 @@ namespace Microsoft.AspNetCore.Localization } private static CultureInfo GetCultureInfo( - string cultureName, + StringSegment cultureName, IList supportedCultures, bool fallbackToParentCultures, int currentDepth) @@ -186,7 +187,7 @@ namespace Microsoft.AspNetCore.Localization if (lastIndexOfHyphen > 0) { // Trim the trailing section from the culture name, e.g. "fr-FR" becomes "fr" - var parentCultureName = cultureName.Substring(0, lastIndexOfHyphen); + var parentCultureName = cultureName.Subsegment(0, lastIndexOfHyphen); culture = GetCultureInfo(parentCultureName, supportedCultures, fallbackToParentCultures, currentDepth + 1); } diff --git a/src/Microsoft.AspNetCore.Localization/breakingchanges.netcore.json b/src/Microsoft.AspNetCore.Localization/breakingchanges.netcore.json new file mode 100644 index 0000000000..5568b582c6 --- /dev/null +++ b/src/Microsoft.AspNetCore.Localization/breakingchanges.netcore.json @@ -0,0 +1,32 @@ +[ + { + "TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult", + "MemberId": "public .ctor(System.Collections.Generic.IList cultures)", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult", + "MemberId": "public .ctor(System.Collections.Generic.IList cultures, System.Collections.Generic.IList uiCultures)", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult", + "MemberId": "public .ctor(System.String culture)", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult", + "MemberId": "public .ctor(System.String culture, System.String uiCulture)", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult", + "MemberId": "public System.Collections.Generic.IList get_Cultures()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult", + "MemberId": "public System.Collections.Generic.IList get_UICultures()", + "Kind": "Removal" + } +] \ No newline at end of file