Skip to content
This repository was archived by the owner on Nov 28, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void Main(string[] args)
";

var expected = @"
PC001: RegistryKey.OpenSubKey(string) isn't supported on MacOSX
PC001: RegistryKey.OpenSubKey(string) isn't supported on macOS
";

var settings = @"
Expand Down Expand Up @@ -101,7 +101,7 @@ static void Main(string[] args)

var settings = @"
PlatformCompatIgnore=Linux
MacOSX
macOS
";

AssertNoMatch(source, settings);
Expand Down Expand Up @@ -151,7 +151,7 @@ static void Main(string[] args)
";

var expected = @"
PC001: RegistryKey.OpenSubKey(string) isn't supported on Linux, MacOSX
PC001: RegistryKey.OpenSubKey(string) isn't supported on Linux and macOS
";

AssertMatch(source, expected);
Expand All @@ -176,7 +176,7 @@ static void Main(string[] args)
";

var expected = @"
PC001: NamedPipeClientStream.NamedPipeClientStream(string) isn't supported on Linux, MacOSX
PC001: NamedPipeClientStream.NamedPipeClientStream(string) isn't supported on Linux and macOS
";

AssertMatch(source, expected);
Expand All @@ -201,7 +201,7 @@ static void Main(string[] args)
";

var expected = @"
PC001: Console.WindowWidth isn't supported on Linux, MacOSX
PC001: Console.WindowWidth isn't supported on Linux and macOS
";

AssertMatch(source, expected);
Expand Down Expand Up @@ -231,7 +231,7 @@ private void MyException_SerializeObjectState(object sender, SafeSerializationEv
";

var expected = @"
PC001: Exception.SerializeObjectState isn't supported on Linux, MacOSX, Windows
PC001: Exception.SerializeObjectState isn't supported on Linux, macOS, and Windows
";

AssertMatch(source, expected);
Expand All @@ -258,7 +258,7 @@ static void Main(string[] args)
";

var expected = @"
PC001: CngAlgorithm.operator ==(CngAlgorithm, CngAlgorithm) isn't supported on Linux, MacOSX
PC001: CngAlgorithm.operator ==(CngAlgorithm, CngAlgorithm) isn't supported on Linux and macOS
";

AssertMatch(source, expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void AnalyzeSymbol(SymbolUsageAnalysisContext context, PlatformCompatOpt

var api = symbol.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat);
var location = context.GetLocation();
var list = maskedPlatforms.ToString();
var list = maskedPlatforms.ToFriendlyString();
var diagnostic = Diagnostic.Create(Rule, location, api, list);
context.ReportDiagnostic(diagnostic);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static bool TryParsePlatformName(string text, out Platform platform)
platform = Platform.Linux;
return true;
case "osx":
platform = Platform.MacOSX;
platform = Platform.MacOS;
return true;
case "win":
platform = Platform.Windows;
Expand Down
50 changes: 49 additions & 1 deletion src/Microsoft.DotNet.Analyzers.Compatibility/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,55 @@ public enum Platform
{
None = 0,
Linux = 1,
MacOSX = 2,
MacOS = 2,
Windows = 4
}

public static class PlatformEnumHelpers
{
private const string Linux = "Linux";
private const string MacOS = "macOS";
private const string Windows = "Windows";

private static readonly string[] s_mapPlatformsToFriendlyString = new[]
{
String.Empty,
Linux,
MacOS,
$"{Linux} and {MacOS}",
$"{Windows}",
$"{Linux} and {Windows}",
$"{MacOS} and {Windows}",
$"{Linux}, {MacOS}, and {Windows}"
};

public static string ToFriendlyString(this Platform platform)
{
var friendlyStringIndex = (int)platform;
if (friendlyStringIndex < 0 && friendlyStringIndex >= s_mapPlatformsToFriendlyString.Length)
throw new ArgumentOutOfRangeException(nameof(platform));

return s_mapPlatformsToFriendlyString[friendlyStringIndex];
}

public static bool TryParse(string trimmedPlatformName, out Platform platform)
{
platform = Platform.None;

switch (trimmedPlatformName)
{
case Linux:
platform = Platform.Linux;
break;
case MacOS:
platform = Platform.MacOS;
break;
case Windows:
platform = Platform.Windows;
break;
}

return platform != Platform.None;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Platform ParseIgnoredPlatforms(ImmutableDictionary<string, string>
foreach (var name in names)
{
var trimmedNamed = name.Trim();
if (Enum.TryParse<Platform>(trimmedNamed, out var platform))
if (PlatformEnumHelpers.TryParse(trimmedNamed, out var platform))
result |= platform;
}
}
Expand Down