Obsolete ResourceManagerWithCultureStringLocalizer and WithCulture (dotnet/extensions#1133)

Obsolete ResourceManagerWithCultureStringLocalizer and WithCulture
\n\nCommit migrated from 924015e98b
This commit is contained in:
Ryan Brandenburg 2019-02-20 11:43:55 -08:00 committed by GitHub
parent ffd47e1bd8
commit 58ea57e63f
7 changed files with 23 additions and 15 deletions

View File

@ -8,6 +8,7 @@ namespace Microsoft.Extensions.Localization
Microsoft.Extensions.Localization.LocalizedString this[string name] { get; } Microsoft.Extensions.Localization.LocalizedString this[string name] { get; }
Microsoft.Extensions.Localization.LocalizedString this[string name, params object[] arguments] { get; } Microsoft.Extensions.Localization.LocalizedString this[string name, params object[] arguments] { get; }
System.Collections.Generic.IEnumerable<Microsoft.Extensions.Localization.LocalizedString> GetAllStrings(bool includeParentCultures); System.Collections.Generic.IEnumerable<Microsoft.Extensions.Localization.LocalizedString> GetAllStrings(bool includeParentCultures);
[System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")]
Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture); Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture);
} }
public partial interface IStringLocalizerFactory public partial interface IStringLocalizerFactory
@ -42,6 +43,7 @@ namespace Microsoft.Extensions.Localization
public virtual Microsoft.Extensions.Localization.LocalizedString this[string name] { get { throw null; } } public virtual Microsoft.Extensions.Localization.LocalizedString this[string name] { get { throw null; } }
public virtual Microsoft.Extensions.Localization.LocalizedString this[string name, params object[] arguments] { get { throw null; } } public virtual Microsoft.Extensions.Localization.LocalizedString this[string name, params object[] arguments] { get { throw null; } }
public System.Collections.Generic.IEnumerable<Microsoft.Extensions.Localization.LocalizedString> GetAllStrings(bool includeParentCultures) { throw null; } public System.Collections.Generic.IEnumerable<Microsoft.Extensions.Localization.LocalizedString> GetAllStrings(bool includeParentCultures) { throw null; }
[System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")]
public virtual Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture) { throw null; } public virtual Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture) { throw null; }
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@ -40,6 +41,7 @@ namespace Microsoft.Extensions.Localization
/// </summary> /// </summary>
/// <param name="culture">The <see cref="CultureInfo"/> to use.</param> /// <param name="culture">The <see cref="CultureInfo"/> to use.</param>
/// <returns>A culture-specific <see cref="IStringLocalizer"/>.</returns> /// <returns>A culture-specific <see cref="IStringLocalizer"/>.</returns>
[Obsolete("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")]
IStringLocalizer WithCulture(CultureInfo culture); IStringLocalizer WithCulture(CultureInfo culture);
} }
} }

View File

@ -1,5 +1,5 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -30,6 +30,7 @@ namespace Microsoft.Extensions.Localization
} }
/// <inheritdoc /> /// <inheritdoc />
[Obsolete("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")]
public virtual IStringLocalizer WithCulture(CultureInfo culture) => _localizer.WithCulture(culture); public virtual IStringLocalizer WithCulture(CultureInfo culture) => _localizer.WithCulture(culture);
/// <inheritdoc /> /// <inheritdoc />
@ -64,4 +65,4 @@ namespace Microsoft.Extensions.Localization
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures) => public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures) =>
_localizer.GetAllStrings(includeParentCultures); _localizer.GetAllStrings(includeParentCultures);
} }
} }

View File

@ -36,6 +36,7 @@ namespace Microsoft.Extensions.Localization
public virtual System.Collections.Generic.IEnumerable<Microsoft.Extensions.Localization.LocalizedString> GetAllStrings(bool includeParentCultures) { throw null; } public virtual System.Collections.Generic.IEnumerable<Microsoft.Extensions.Localization.LocalizedString> GetAllStrings(bool includeParentCultures) { throw null; }
protected System.Collections.Generic.IEnumerable<Microsoft.Extensions.Localization.LocalizedString> GetAllStrings(bool includeParentCultures, System.Globalization.CultureInfo culture) { throw null; } protected System.Collections.Generic.IEnumerable<Microsoft.Extensions.Localization.LocalizedString> GetAllStrings(bool includeParentCultures, System.Globalization.CultureInfo culture) { throw null; }
protected string GetStringSafely(string name, System.Globalization.CultureInfo culture) { throw null; } protected string GetStringSafely(string name, System.Globalization.CultureInfo culture) { throw null; }
[System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")]
public Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture) { throw null; } public Microsoft.Extensions.Localization.IStringLocalizer WithCulture(System.Globalization.CultureInfo culture) { throw null; }
} }
public partial class ResourceManagerStringLocalizerFactory : Microsoft.Extensions.Localization.IStringLocalizerFactory public partial class ResourceManagerStringLocalizerFactory : Microsoft.Extensions.Localization.IStringLocalizerFactory
@ -51,6 +52,7 @@ namespace Microsoft.Extensions.Localization
protected virtual string GetResourcePrefix(string location, string baseName, string resourceLocation) { throw null; } protected virtual string GetResourcePrefix(string location, string baseName, string resourceLocation) { throw null; }
protected virtual Microsoft.Extensions.Localization.RootNamespaceAttribute GetRootNamespaceAttribute(System.Reflection.Assembly assembly) { throw null; } protected virtual Microsoft.Extensions.Localization.RootNamespaceAttribute GetRootNamespaceAttribute(System.Reflection.Assembly assembly) { throw null; }
} }
[System.ObsoleteAttribute("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")]
public partial class ResourceManagerWithCultureStringLocalizer : Microsoft.Extensions.Localization.ResourceManagerStringLocalizer public partial class ResourceManagerWithCultureStringLocalizer : Microsoft.Extensions.Localization.ResourceManagerStringLocalizer
{ {
public ResourceManagerWithCultureStringLocalizer(System.Resources.ResourceManager resourceManager, System.Reflection.Assembly resourceAssembly, string baseName, Microsoft.Extensions.Localization.IResourceNamesCache resourceNamesCache, System.Globalization.CultureInfo culture, Microsoft.Extensions.Logging.ILogger logger) : base (default(System.Resources.ResourceManager), default(System.Reflection.Assembly), default(string), default(Microsoft.Extensions.Localization.IResourceNamesCache), default(Microsoft.Extensions.Logging.ILogger)) { } public ResourceManagerWithCultureStringLocalizer(System.Resources.ResourceManager resourceManager, System.Reflection.Assembly resourceAssembly, string baseName, Microsoft.Extensions.Localization.IResourceNamesCache resourceNamesCache, System.Globalization.CultureInfo culture, Microsoft.Extensions.Logging.ILogger logger) : base (default(System.Resources.ResourceManager), default(System.Reflection.Assembly), default(string), default(Microsoft.Extensions.Localization.IResourceNamesCache), default(Microsoft.Extensions.Logging.ILogger)) { }

View File

@ -1,5 +1,5 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
@ -151,6 +151,7 @@ namespace Microsoft.Extensions.Localization
/// </summary> /// </summary>
/// <param name="culture">The <see cref="CultureInfo"/> to use.</param> /// <param name="culture">The <see cref="CultureInfo"/> to use.</param>
/// <returns>A culture-specific <see cref="ResourceManagerStringLocalizer"/>.</returns> /// <returns>A culture-specific <see cref="ResourceManagerStringLocalizer"/>.</returns>
[Obsolete("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")]
public IStringLocalizer WithCulture(CultureInfo culture) public IStringLocalizer WithCulture(CultureInfo culture)
{ {
return culture == null return culture == null
@ -271,4 +272,4 @@ namespace Microsoft.Extensions.Localization
return resourceNames; return resourceNames;
} }
} }
} }

View File

@ -1,5 +1,5 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -15,6 +15,7 @@ namespace Microsoft.Extensions.Localization
/// An <see cref="IStringLocalizer"/> that uses the <see cref="ResourceManager"/> and /// An <see cref="IStringLocalizer"/> that uses the <see cref="ResourceManager"/> and
/// <see cref="ResourceReader"/> to provide localized strings for a specific <see cref="CultureInfo"/>. /// <see cref="ResourceReader"/> to provide localized strings for a specific <see cref="CultureInfo"/>.
/// </summary> /// </summary>
[Obsolete("This method is obsolete. Use `CurrentCulture` and `CurrentUICulture` instead.")]
public class ResourceManagerWithCultureStringLocalizer : ResourceManagerStringLocalizer public class ResourceManagerWithCultureStringLocalizer : ResourceManagerStringLocalizer
{ {
private readonly string _resourceBaseName; private readonly string _resourceBaseName;
@ -161,4 +162,4 @@ namespace Microsoft.Extensions.Localization
public override IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures) => public override IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures) =>
GetAllStrings(includeParentCultures, _culture); GetAllStrings(includeParentCultures, _culture);
} }
} }

View File

@ -182,12 +182,11 @@ namespace Microsoft.Extensions.Localization
var resourceManager = new TestResourceManager(baseName, resourceAssembly); var resourceManager = new TestResourceManager(baseName, resourceAssembly);
var logger = Logger; var logger = Logger;
var localizer = new ResourceManagerWithCultureStringLocalizer( var localizer = new ResourceManagerStringLocalizer(
resourceManager, resourceManager,
resourceAssembly.Assembly, resourceAssembly.Assembly,
baseName, baseName,
resourceNamesCache, resourceNamesCache,
CultureInfo.CurrentCulture,
logger); logger);
// Act & Assert // Act & Assert
@ -291,7 +290,7 @@ namespace Microsoft.Extensions.Localization
public override Stream GetManifestResourceStream(string name) public override Stream GetManifestResourceStream(string name)
{ {
ManifestResourceStreamCallCount++; ManifestResourceStreamCallCount++;
return HasResources ? MakeResourceStream() : null; return HasResources ? MakeResourceStream() : null;
} }
} }