-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
RequestLocalizationOptionsExtensions.cs
31 lines (26 loc) · 1.47 KB
/
RequestLocalizationOptionsExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.AspNetCore.Localization;
namespace Microsoft.AspNetCore.Builder;
/// <summary>
/// Extension methods for the <see cref="RequestLocalizationOptions"/>.
/// </summary>
public static class RequestLocalizationOptionsExtensions
{
/// <summary>
/// Adds a new <see cref="RequestCultureProvider"/> to the <see cref="RequestLocalizationOptions.RequestCultureProviders"/>.
/// </summary>
/// <param name="requestLocalizationOptions">The cultures to be added.</param>
/// <param name="requestCultureProvider">The cultures to be added.</param>
/// <returns>The <see cref="RequestLocalizationOptions"/>.</returns>
/// <remarks>This method ensures that <paramref name="requestCultureProvider"/> has priority over other <see cref="RequestCultureProvider"/> instances in <see cref="RequestLocalizationOptions.RequestCultureProviders"/>.</remarks>
public static RequestLocalizationOptions AddInitialRequestCultureProvider(
this RequestLocalizationOptions requestLocalizationOptions,
RequestCultureProvider requestCultureProvider)
{
ArgumentNullException.ThrowIfNull(requestLocalizationOptions);
ArgumentNullException.ThrowIfNull(requestCultureProvider);
requestLocalizationOptions.RequestCultureProviders.Insert(0, requestCultureProvider);
return requestLocalizationOptions;
}
}