Move CultureInfoCache into its own package.
This commit is contained in:
parent
805dc3f25b
commit
2431e1a542
|
|
@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CultureInfoGenerator", "src\CultureInfoGenerator\CultureInfoGenerator.xproj", "{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CultureInfoGenerator", "src\CultureInfoGenerator\CultureInfoGenerator.xproj", "{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Framework.Globalization.CultureInfoCache", "src\Microsoft.Framework.Globalization.CultureInfoCache\Microsoft.Framework.Globalization.CultureInfoCache.xproj", "{F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|
@ -48,6 +50,10 @@ Global
|
||||||
{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}.Release|Any CPU.Build.0 = Release|Any CPU
|
{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
@ -58,5 +64,6 @@ Global
|
||||||
{A1FCF259-70F6-4605-AA2D-E4B356BE771A} = {FB313677-BAB3-4E49-8CDB-4FA4A9564767}
|
{A1FCF259-70F6-4605-AA2D-E4B356BE771A} = {FB313677-BAB3-4E49-8CDB-4FA4A9564767}
|
||||||
{55D9501F-15B9-4339-A0AB-6082850E5FCE} = {79878809-8D1C-4BD4-BA99-F1F13FF96FD8}
|
{55D9501F-15B9-4339-A0AB-6082850E5FCE} = {79878809-8D1C-4BD4-BA99-F1F13FF96FD8}
|
||||||
{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB} = {FB313677-BAB3-4E49-8CDB-4FA4A9564767}
|
{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB} = {FB313677-BAB3-4E49-8CDB-4FA4A9564767}
|
||||||
|
{F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A} = {FB313677-BAB3-4E49-8CDB-4FA4A9564767}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ namespace CultureInfoGenerator
|
||||||
|
|
||||||
public void Main(string[] args)
|
public void Main(string[] args)
|
||||||
{
|
{
|
||||||
var outputFilePath = args.Length > 0 ? args[0] : Path.Combine(_appPath, "../Microsoft.AspNet.Localization/Internal/CultureInfoList.cs");
|
var outputFilePath = args.Length > 0 ? args[0] : Path.Combine(_appPath, "../Microsoft.Framework.Globalization.CultureCache/CultureInfoList.cs");
|
||||||
var netFxVersion = Get45or451FromRegistry();
|
var netFxVersion = Get45or451FromRegistry();
|
||||||
var windowsVersion = Environment.OSVersion;
|
var windowsVersion = Environment.OSVersion;
|
||||||
|
|
||||||
|
|
@ -31,16 +31,24 @@ namespace CultureInfoGenerator
|
||||||
writer.WriteLine($@"// Copyright (c) .NET Foundation. All rights reserved.
|
writer.WriteLine($@"// 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.
|
||||||
|
|
||||||
|
// *************************** THIS FILE IS GENERATED BY A TOOL ***************************
|
||||||
|
// To make changes to this file look at the CultureInfoGenerator project in this solution.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Localization.Internal
|
namespace Microsoft.Framework.Globalization
|
||||||
{{
|
{{
|
||||||
public static class CultureInfoList
|
/// <summary>
|
||||||
|
/// Contains a list of known culture names that can be used to create a <see cref=""System.Globalization.CultureInfo""/>.
|
||||||
|
/// </summary>
|
||||||
|
public static partial class CultureInfoCache
|
||||||
{{
|
{{
|
||||||
// This list of known cultures was generated by {_appName} using .NET Framework {netFxVersion} on
|
/// <summary>
|
||||||
// {windowsVersion}.
|
/// This list of known cultures was generated by {_appName} using .NET Framework {netFxVersion} on
|
||||||
// As new versions of .NET Framework and Windows are released, this list should be regenerated to ensure it
|
/// {windowsVersion}.
|
||||||
// contains the latest culture names.
|
/// As new versions of .NET Framework and Windows are released, this list should be regenerated to ensure it
|
||||||
|
/// contains the latest culture names.
|
||||||
|
/// </summary>
|
||||||
public static readonly HashSet<string> KnownCultureNames = new HashSet<string>
|
public static readonly HashSet<string> KnownCultureNames = new HashSet<string>
|
||||||
{{"
|
{{"
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Localization.Internal;
|
using Microsoft.Framework.Globalization;
|
||||||
using Microsoft.Framework.Internal;
|
using Microsoft.Framework.Internal;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Localization.Internal;
|
using Microsoft.Framework.Globalization;
|
||||||
using Microsoft.Framework.Internal;
|
using Microsoft.Framework.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Localization
|
namespace Microsoft.AspNet.Localization
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Localization.Internal;
|
using Microsoft.Framework.Globalization;
|
||||||
using Microsoft.Framework.Internal;
|
using Microsoft.Framework.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Localization
|
namespace Microsoft.AspNet.Localization
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@
|
||||||
"description": "Middleware for automatically applying culture information to HTTP requests.",
|
"description": "Middleware for automatically applying culture information to HTTP requests.",
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"Microsoft.AspNet.Http.Extensions": "1.0.0-*",
|
||||||
|
"Microsoft.Framework.Globalization.CultureInfoCache": "1.0.0-*",
|
||||||
"Microsoft.Framework.Localization.Abstractions": "1.0.0-*",
|
"Microsoft.Framework.Localization.Abstractions": "1.0.0-*",
|
||||||
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" },
|
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }
|
||||||
"Microsoft.AspNet.Http.Extensions": "1.0.0-*"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
|
|
@ -13,7 +14,6 @@
|
||||||
"dnxcore50": {
|
"dnxcore50": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"System.Collections": "4.0.10-*",
|
"System.Collections": "4.0.10-*",
|
||||||
"System.Collections.Concurrent": "4.0.10-*",
|
|
||||||
"System.Linq": "4.0.0-*",
|
"System.Linq": "4.0.0-*",
|
||||||
"System.Globalization": "4.0.10-*",
|
"System.Globalization": "4.0.10-*",
|
||||||
"System.Threading": "4.0.10-*",
|
"System.Threading": "4.0.10-*",
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,32 @@
|
||||||
// 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.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Localization.Internal
|
namespace Microsoft.Framework.Globalization
|
||||||
{
|
{
|
||||||
public static class CultureInfoCache
|
/// <summary>
|
||||||
|
/// Provides read-only cached instances of <see cref="CultureInfo"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static partial class CultureInfoCache
|
||||||
{
|
{
|
||||||
private static readonly ConcurrentDictionary<string, CacheEntry> _cache = new ConcurrentDictionary<string, CacheEntry>();
|
private static readonly ConcurrentDictionary<string, CacheEntry> _cache = new ConcurrentDictionary<string, CacheEntry>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a read-only cached <see cref="CultureInfo"/> for the specified name. Only names that exist in
|
||||||
|
/// <see cref="KnownCultureNames"/> will be used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The culture name.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// A read-only cached <see cref="CultureInfo"/> or <c>null</c> a match wasn't found in
|
||||||
|
/// <see cref="KnownCultureNames"/>.
|
||||||
|
/// </returns>
|
||||||
public static CultureInfo GetCultureInfo(string name)
|
public static CultureInfo GetCultureInfo(string name)
|
||||||
{
|
{
|
||||||
// Allow only known culture names as this API is called with input from users (HTTP requests) and
|
// 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.
|
// creating CultureInfo objects is expensive and we don't want it to throw either.
|
||||||
if (name == null || !CultureInfoList.KnownCultureNames.Contains(name))
|
if (name == null || !KnownCultureNames.Contains(name))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -1,16 +1,24 @@
|
||||||
// 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.
|
||||||
|
|
||||||
|
// *************************** THIS FILE IS GENERATED BY A TOOL ***************************
|
||||||
|
// To make changes to this file look at the CultureInfoGenerator project in this solution.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Localization.Internal
|
namespace Microsoft.Framework.Globalization
|
||||||
{
|
{
|
||||||
public static class CultureInfoList
|
/// <summary>
|
||||||
|
/// Contains a list of known culture names that can be used to create a <see cref="System.Globalization.CultureInfo"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static partial class CultureInfoCache
|
||||||
{
|
{
|
||||||
// This list of known cultures was generated by CultureInfoGenerator using .NET Framework 4.6 RC or later on
|
/// <summary>
|
||||||
// Microsoft Windows NT 6.2.9200.0.
|
/// This list of known cultures was generated by CultureInfoGenerator using .NET Framework 4.6 RC or later on
|
||||||
// As new versions of .NET Framework and Windows are released, this list should be regenerated to ensure it
|
/// Microsoft Windows NT 6.2.9200.0.
|
||||||
// contains the latest culture names.
|
/// As new versions of .NET Framework and Windows are released, this list should be regenerated to ensure it
|
||||||
|
/// contains the latest culture names.
|
||||||
|
/// </summary>
|
||||||
public static readonly HashSet<string> KnownCultureNames = new HashSet<string>
|
public static readonly HashSet<string> KnownCultureNames = new HashSet<string>
|
||||||
{
|
{
|
||||||
"",
|
"",
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<ProjectGuid>f3988d3a-a4c8-4fd7-bafe-13e0d0a1659a</ProjectGuid>
|
||||||
|
<RootNamespace>Microsoft.Framework.Globalization.CultureInfoList</RootNamespace>
|
||||||
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||||
|
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.0-*",
|
||||||
|
"description": "Provides cached instances of CultureInfo using a generated list of known culture names for use in scenarios where unbounded CultureInfo creation is undesirable.",
|
||||||
|
|
||||||
|
"dependencies": {
|
||||||
|
},
|
||||||
|
|
||||||
|
"frameworks": {
|
||||||
|
"dnx451": { },
|
||||||
|
"dnxcore50": {
|
||||||
|
"dependencies": {
|
||||||
|
"System.Collections": "4.0.10-*",
|
||||||
|
"System.Collections.Concurrent": "4.0.10-*",
|
||||||
|
"System.Globalization": "4.0.10-*",
|
||||||
|
"Microsoft.CSharp": "4.0.0-*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue