Move EncodingUtilities to Framework (#8620)

This will single-instance it for improved performance.
This commit is contained in:
Rainer Sigwald 2023-04-03 21:01:04 -05:00 коммит произвёл GitHub
Родитель 7dd2fa9d5a
Коммит 1241b599d3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 6 добавлений и 16 удалений

Просмотреть файл

@ -35,9 +35,6 @@
<Compile Include="..\Shared\EncodingStringWriter.cs">
<Link>EncodingStringWriter.cs</Link>
</Compile>
<Compile Include="..\Shared\EncodingUtilities.cs">
<Link>EncodingUtilities.cs</Link>
</Compile>
<Compile Include="..\Shared\UnitTests\ObjectModelHelpers.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>

Просмотреть файл

@ -56,9 +56,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="..\Shared\EncodingUtilities.cs">
<Link>SharedUtilities\EncodingUtilities.cs</Link>
</Compile>
<Compile Include="..\Shared\EnvironmentUtilities.cs">
<Link>SharedUtilities\EnvironmentUtilities.cs</Link>
</Compile>

Просмотреть файл

@ -7,6 +7,8 @@ using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Build.Framework;
#nullable disable
namespace Microsoft.Build.Shared
@ -48,17 +50,17 @@ namespace Microsoft.Build.Shared
try
{
if (NativeMethodsShared.IsWindows)
if (NativeMethods.IsWindows)
{
#if RUNTIME_TYPE_NETCORE
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
#endif
// get the current OEM code page
s_currentOemEncoding = Encoding.GetEncoding(NativeMethodsShared.GetOEMCP());
s_currentOemEncoding = Encoding.GetEncoding(NativeMethods.GetOEMCP());
}
}
// theoretically, GetEncoding may throw an ArgumentException or a NotSupportedException. This should never
// really happen, since the code page we pass in has just been returned from the "underlying platform",
// really happen, since the code page we pass in has just been returned from the "underlying platform",
// so it really should support it. If it ever happens, we'll just fall back to the default encoding.
// No point in showing any errors to the users, since they most likely wouldn't be actionable.
catch (ArgumentException ex)
@ -214,7 +216,7 @@ namespace Microsoft.Build.Shared
/// </remarks>
internal static Encoding BatchFileEncoding(string contents, string encodingSpecification)
{
if (!NativeMethodsShared.IsWindows)
if (!NativeMethods.IsWindows)
{
return EncodingUtilities.Utf8WithoutBom;
}

Просмотреть файл

@ -150,9 +150,6 @@
<Compile Include="..\Shared\AssemblyNameExtension.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="..\Shared\EncodingUtilities.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="..\Shared\ErrorUtilities.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>

Просмотреть файл

@ -72,9 +72,6 @@
<Compile Include="..\Shared\CopyOnWriteDictionary.cs">
<Link>Shared\CopyOnWriteDictionary.cs</Link>
</Compile>
<Compile Include="..\Shared\EncodingUtilities.cs">
<Link>Shared\EncodingUtilities.cs</Link>
</Compile>
<Compile Include="..\Shared\ErrorUtilities.cs">
<Link>Shared\ErrorUtilities.cs</Link>
</Compile>