Files
dotnet-runtime/src/libraries/System.Runtime.Serialization.Formatters/tests/PlatformExtensions.cs
T
Stephen Toub 60d1224ddd Re-enable StyleCop warnings SA1028 and SA1518 (trailing whitespace and blank lines) (dotnet/corefx#40113)
Mechanical/automated change.  The only manual changes were a) removing the two rules from the CodeAnalysis.ruleset file, b) removing spaces from one line of a .targets file that is used to generate a .cs file, and c) reverting the changes in a few test files where the naive replacement happened in the middle of a verbatim string where the whitespace actually mattered.

Commit migrated from https://github.com/dotnet/corefx/commit/09a6e66b0c2b31bd0f6e7e3170537d14027aeed0
2019-08-07 21:07:58 -04:00

71 lines
2.7 KiB
C#

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace System.Runtime.Serialization.Formatters.Tests
{
internal static class PlatformExtensions
{
private static bool IsNetFxPatchedVersion(int build)
{
string versionRaw = RuntimeInformation.FrameworkDescription.Replace(".NET Framework", "").Trim();
if (Version.TryParse(versionRaw, out Version version))
{
return version.Build >= build;
}
return false;
}
public static int GetPlatformIndex(this TypeSerializableValue[] blobs)
{
List<TypeSerializableValue> blobList = blobs.ToList();
int index;
// .NET Framework
if (PlatformDetection.IsFullFramework)
{
// Check if a specialized blob for >=netfx472 build 3260 is present and return if found.
if (IsNetFxPatchedVersion(3260))
{
index = blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netfx472_3260);
if (index >= 0)
return index;
}
index = blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netfx472);
if (index >= 0)
return index;
index = blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netfx471);
if (index >= 0)
return index;
// If no newer blob for >=netfx471 is present use existing one.
// If no netfx blob is present then -1 will be returned.
return blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netfx461);
}
// Check if a specialized blob for >=netcoreapp3.0 is present and return if found.
index = blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netcoreapp30);
if (index >= 0)
return index;
// Check if a specialized blob for netcoreapp2.1 is present and return if found.
index = blobList.FindIndex(b => b.Platform == TargetFrameworkMoniker.netcoreapp21);
if (index >= 0)
return index;
// If no newer blob for >=netcoreapp2.1 is present use existing one.
// If no netcoreapp blob is present then -1 will be returned.
return blobList.FindIndex((b => b.Platform == TargetFrameworkMoniker.netcoreapp20));
}
}
}