From 14ac3c9e2e607433716a251761aecc79bf55ac09 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Saenz Date: Wed, 17 Sep 2025 14:47:52 -0400 Subject: [PATCH 1/6] [RGen] Add a new type to track versions. When adding a platform to a symbol it might be the case that the addition has an implication for another platform. For example, when we add support for iOS we are adding support for Catalyst. This new struct keeps track of the reason why a version was added and will allow to choose always the Explicit verison when two versions are compared. This will later can be used with the Builder class to add Implicit versions for a platform and be able to calculate which version to use. --- .../Availability/PlatformSupportVersion.cs | 70 ++++++++ .../Availability/SupportKind.cs | 9 + .../PlatformSupportVersionTests.cs | 160 ++++++++++++++++++ 3 files changed, 239 insertions(+) create mode 100644 src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs create mode 100644 src/rgen/Microsoft.Macios.Generator/Availability/SupportKind.cs create mode 100644 tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformSupportVersionTests.cs diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs new file mode 100644 index 00000000000..b803911c6b4 --- /dev/null +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; + +namespace Microsoft.Macios.Generator.Availability; + +/// +/// Represents a platform support version, combining a version number and a support kind. +/// +public readonly record struct PlatformSupportVersion { + /// + /// Gets the version number. + /// + public Version Version { get; init; } + /// + /// Gets the kind of support (e.g., explicit, implicit). + /// + public SupportKind Kind { get; init; } + + /// + /// Gets a default platform support version with an implicit kind. + /// + public static PlatformSupportVersion ImplicitDefault { get; } = new () { + Version = new (), + Kind = SupportKind.Implicit + }; + + /// + /// Gets a default platform support version with an explicit kind. + /// + public static PlatformSupportVersion ExplicitDefault { get; } = new () { + Version = new (), + Kind = SupportKind.Explicit + }; + + /// + /// Returns the platform support version with the highest precedence. + /// + /// The first platform support version to compare. + /// The second platform support version to compare. + /// + /// The platform support version with the highest precedence. If the kinds are the same, it returns the one with the greater version. + /// If the kinds are different, it returns the one with the higher kind value. + /// + public static PlatformSupportVersion Max (PlatformSupportVersion v1, PlatformSupportVersion v2) + { + if (v1.Kind == v2.Kind) { + return v1.Version >= v2.Version ? v1 : v2; + } + return (int) v1.Kind > (int) v2.Kind ? v1 : v2; + } + + /// + /// Returns the platform support version with the lowest version if the kinds are the same, otherwise returns the one with the highest precedence kind. + /// + /// The first platform support version to compare. + /// The second platform support version to compare. + /// + /// The platform support version with the lowest version if the kinds are the same. + /// If the kinds are different, it returns the one with the higher kind value. + /// + public static PlatformSupportVersion Min (PlatformSupportVersion v1, PlatformSupportVersion v2) + { + if (v1.Kind == v2.Kind) { + return v1.Version <= v2.Version ? v1 : v2; + } + return (int) v1.Kind > (int) v2.Kind ? v1 : v2; + } +} diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/SupportKind.cs b/src/rgen/Microsoft.Macios.Generator/Availability/SupportKind.cs new file mode 100644 index 00000000000..9c5f7960ea8 --- /dev/null +++ b/src/rgen/Microsoft.Macios.Generator/Availability/SupportKind.cs @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Macios.Generator.Availability; + +public enum SupportKind { + Implicit, + Explicit +} diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformSupportVersionTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformSupportVersionTests.cs new file mode 100644 index 00000000000..eb4fb74991b --- /dev/null +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformSupportVersionTests.cs @@ -0,0 +1,160 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using Microsoft.Macios.Generator.Availability; +using Xunit; + +namespace Microsoft.Macios.Generator.Tests.Availability; + +public class PlatformSupportVersionTests { + [Fact] + public void ImplicitDefaultTest () + { + var implicitDefault = PlatformSupportVersion.ImplicitDefault; + Assert.Equal (new Version (0, 0), implicitDefault.Version); + Assert.Equal (SupportKind.Implicit, implicitDefault.Kind); + } + + [Fact] + public void ExplicitDefaultTest () + { + var explicitDefault = PlatformSupportVersion.ExplicitDefault; + Assert.Equal (new Version (0, 0), explicitDefault.Version); + Assert.Equal (SupportKind.Explicit, explicitDefault.Kind); + } + + public static TheoryData MaxTestData => + new () { + // Same kind, v1 > v2 + { + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit } + }, + // Same kind, v2 > v1 + { + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit } + }, + // Same kind, v1 == v2 + { + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit } + }, + // Different kind, v1.Kind > v2.Kind + { + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit }, + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit } + }, + // Different kind, v2.Kind > v1.Kind + { + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit } + }, + // ExplicitDefault vs ImplicitDefault + { + PlatformSupportVersion.ExplicitDefault, + PlatformSupportVersion.ImplicitDefault, + PlatformSupportVersion.ExplicitDefault + }, + // ExplicitDefault vs other Implicit + { + PlatformSupportVersion.ExplicitDefault, + new PlatformSupportVersion { Version = new Version (10, 0), Kind = SupportKind.Implicit }, + PlatformSupportVersion.ExplicitDefault + }, + // ImplicitDefault vs other Implicit + { + PlatformSupportVersion.ImplicitDefault, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit } + }, + // ExplicitDefault vs other Explicit + { + PlatformSupportVersion.ExplicitDefault, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit } + }, + }; + + [Theory] + [MemberData (nameof (MaxTestData))] + public void MaxTests (PlatformSupportVersion v1, PlatformSupportVersion v2, PlatformSupportVersion expected) + { + Assert.Equal (expected, PlatformSupportVersion.Max (v1, v2)); + // Test commutativity + Assert.Equal (expected, PlatformSupportVersion.Max (v2, v1)); + } + + public static TheoryData MinTestData => + new () { + // Same kind, v1 < v2 + { + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit } + }, + // Same kind, v2 < v1 + { + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit } + }, + // Same kind, v1 == v2 + { + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit } + }, + // Different kind, v1.Kind > v2.Kind + { + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Explicit }, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Explicit } + }, + // Different kind, v2.Kind > v1.Kind + { + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Explicit }, + new PlatformSupportVersion { Version = new Version (2, 0), Kind = SupportKind.Explicit } + }, + // ExplicitDefault vs ImplicitDefault + { + PlatformSupportVersion.ExplicitDefault, + PlatformSupportVersion.ImplicitDefault, + PlatformSupportVersion.ExplicitDefault + }, + // ExplicitDefault vs other Implicit + { + PlatformSupportVersion.ExplicitDefault, + new PlatformSupportVersion { Version = new Version (10, 0), Kind = SupportKind.Implicit }, + PlatformSupportVersion.ExplicitDefault + }, + // ImplicitDefault vs other Implicit + { + PlatformSupportVersion.ImplicitDefault, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Implicit }, + PlatformSupportVersion.ImplicitDefault + }, + // ExplicitDefault vs other Explicit + { + PlatformSupportVersion.ExplicitDefault, + new PlatformSupportVersion { Version = new Version (1, 0), Kind = SupportKind.Explicit }, + PlatformSupportVersion.ExplicitDefault + }, + }; + + [Theory] + [MemberData (nameof (MinTestData))] + public void MinTests (PlatformSupportVersion v1, PlatformSupportVersion v2, PlatformSupportVersion expected) + { + Assert.Equal (expected, PlatformSupportVersion.Min (v1, v2)); + // Test commutativity + Assert.Equal (expected, PlatformSupportVersion.Min (v2, v1)); + } +} From 382ee7ed33b5408b73472582687fd2fb00786f7c Mon Sep 17 00:00:00 2001 From: GitHub Actions Autoformatter Date: Wed, 17 Sep 2025 18:54:26 +0000 Subject: [PATCH 2/6] Auto-format source code --- .../Availability/PlatformSupportVersion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs index b803911c6b4..65cf6864b39 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs @@ -30,7 +30,7 @@ public readonly record struct PlatformSupportVersion { /// Gets a default platform support version with an explicit kind. /// public static PlatformSupportVersion ExplicitDefault { get; } = new () { - Version = new (), + Version = new (), Kind = SupportKind.Explicit }; From 46eb2d3348c234af6055638f12c2c51941be5f48 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Saenz Date: Wed, 17 Sep 2025 17:06:59 -0400 Subject: [PATCH 3/6] [RGen] Use the new PlatformSupportVersion in the builder. Do not change the behaviour just yet but use the new struct in the builder to ensure that we will later be able to add support to implicit/explicit versions. --- .../Availability/PlatformAvailability.cs | 6 +- .../PlatformAvailabilityBuilder.cs | 37 ++++++---- .../Availability/PlatformSupportVersion.cs | 17 +++++ .../PlatformSupportVersionComparer.cs | 25 +++++++ .../Availability/SymbolAvailabilityBuilder.cs | 4 +- .../PlatformAvailabilityEqualityTests.cs | 20 +++--- .../PlatformAvailabilityMergeTests.cs | 68 +++++++++---------- .../PlatformAvailabilityToStringTests.cs | 16 ++--- 8 files changed, 122 insertions(+), 71 deletions(-) create mode 100644 src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersionComparer.cs diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs index 798d932436c..075951107a3 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs @@ -116,11 +116,11 @@ public PlatformAvailability MergeWithParent (PlatformAvailability? parent) // 1. If the parent has unsupported versions we will add them to the merge. If the kid has them, we will // add them too foreach (var (version, message) in parent.Value.unsupported) { - builder.AddUnsupportedVersion (version, message); + builder.AddUnsupportedVersion (new (version, SupportKind.Explicit), message); } foreach (var (version, message) in unsupported) { - builder.AddUnsupportedVersion (version, message); + builder.AddUnsupportedVersion (new (version, SupportKind.Explicit), message); } // 2. if supported in the platform, we will always pick the larges version between @@ -130,7 +130,7 @@ public PlatformAvailability MergeWithParent (PlatformAvailability? parent) ? parent.Value.SupportedVersion : SupportedVersion; if (supportedVersion is not null) - builder.AddSupportedVersion (supportedVersion); + builder.AddSupportedVersion (new (supportedVersion, SupportKind.Explicit)); // similar to the unsupported versions, if the parent has obsolete ones, we will add them foreach (var (version, obsoleteInfo) in parent.Value.obsoleted) { diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs index 0c9905c9d01..7d05c093ca6 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs @@ -19,9 +19,10 @@ readonly partial struct PlatformAvailability { /// A writable PlatformAvailability accessor. /// public sealed class Builder { + static readonly PlatformSupportVersionComparer versionComparer = new (); readonly ApplePlatform platform; - Version? supportedVersion; - readonly SortedDictionary unsupported = new (); + PlatformSupportVersion? supportedVersion; + readonly SortedDictionary unsupported = new (versionComparer); readonly SortedDictionary obsoleted = new (); /// @@ -36,15 +37,16 @@ public sealed class Builder { /// else the version is ignored. /// /// A new supported version. - internal void AddSupportedVersion (Version version) + internal void AddSupportedVersion (PlatformSupportVersion version) { - if (unsupported.ContainsKey (defaultVersion)) - // platform is unsupported, do nothing + if (unsupported.ContainsKey (PlatformSupportVersion.ExplicitDefault)) + // platform is explicitly unsupported, do nothing return; // update the supported version to the larges of the two - if (supportedVersion is null || version > supportedVersion) - supportedVersion = version; + supportedVersion = supportedVersion is null + ? version + : PlatformSupportVersion.Max (version, supportedVersion.Value); } /// @@ -57,7 +59,7 @@ public void Add (SupportedOSPlatformData supportedPlatform) if (supportedPlatform.Platform != platform) return; // no version is present, therefore try to set the default one - AddSupportedVersion (supportedPlatform.Version); + AddSupportedVersion ( new (supportedPlatform.Version, SupportKind.Explicit)); } /// @@ -65,24 +67,27 @@ public void Add (SupportedOSPlatformData supportedPlatform) /// /// The new unsupported version. /// The optional message of the unsupported version. - internal void AddUnsupportedVersion (Version version, string? message) + internal void AddUnsupportedVersion (PlatformSupportVersion version, string? message) { // adding an unsupported version, due to the way the API is designed is more complicated. It can be // that a selector/member is unsupported in more than one version, so we need to keep track of that // the only time in which we make an exception is when we unsupported a platform (no version number) // if that is the case, we will remove all unsupported versions and just un-support the platform // ignore data from platforms that we do not care - if (version == defaultVersion) { + if (version == PlatformSupportVersion.ExplicitDefault) { unsupported.Clear (); - unsupported [defaultVersion] = message; + unsupported [PlatformSupportVersion.ExplicitDefault] = message; // we are unsupporting the platform! that means if we supported it or any version, that should be // set back to null supportedVersion = null; } else { // we have a version, that does not mean we do care about that data, first we want to check // that we did not fully unsupported the platform, if that is the case, we ignore this version - if (unsupported.ContainsKey (defaultVersion)) + if (unsupported.ContainsKey (PlatformSupportVersion.ExplicitDefault)) return; + + // we implicitly unsupported the platform, remove that entry since we are adding a version + unsupported.Remove (PlatformSupportVersion.ImplicitDefault); unsupported [version] = message; } } @@ -95,7 +100,7 @@ public void Add (UnsupportedOSPlatformData unsupportedPlatform) { if (unsupportedPlatform.Platform != platform) return; - AddUnsupportedVersion (unsupportedPlatform.Version, unsupportedPlatform.Message); + AddUnsupportedVersion (new (unsupportedPlatform.Version, SupportKind.Explicit), unsupportedPlatform.Message); } @@ -137,7 +142,11 @@ public void Add (ObsoletedOSPlatformData obsoletedPlatform) /// A new readonly structure that contains the platform availability. public PlatformAvailability ToImmutable () { - return new PlatformAvailability (platform, supportedVersion, unsupported, obsoleted); + var unsupportedCopy = new SortedDictionary (); + foreach (var (version, message) in unsupported) { + unsupportedCopy.Add (version.Version, message); + } + return new PlatformAvailability (platform, supportedVersion?.Version, unsupportedCopy, obsoleted); } /// diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs index 65cf6864b39..5dc2421f5e4 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs @@ -34,6 +34,23 @@ public readonly record struct PlatformSupportVersion { Kind = SupportKind.Explicit }; + /// + /// Initializes a new instance of the struct. + /// + /// The version number. + /// The kind of support. + public PlatformSupportVersion (Version version, SupportKind kind) + { + Version = version; + Kind = kind; + } + + /// + /// Initializes a new instance of the struct with an explicit support kind. + /// + /// The version number. + public PlatformSupportVersion (Version version) : this(version, SupportKind.Explicit) {} + /// /// Returns the platform support version with the highest precedence. /// diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersionComparer.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersionComparer.cs new file mode 100644 index 00000000000..33f52f300ac --- /dev/null +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersionComparer.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Collections.Generic; + +namespace Microsoft.Macios.Generator.Availability; + +/// +/// Compares two instances for sorting. +/// +public class PlatformSupportVersionComparer : IComparer { + + /// + /// Compares two platform support versions and returns a value indicating whether one is less than, equal to, or greater than the other. + /// + /// The first object to compare. + /// The second object to compare. + /// A signed integer that indicates the relative values of x and y. + public int Compare(PlatformSupportVersion x, PlatformSupportVersion y) + { + int versionComparison = x.Version.CompareTo(y.Version); + if (versionComparison != 0) return versionComparison; + return x.Kind.CompareTo(y.Kind); + } +} diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/SymbolAvailabilityBuilder.cs b/src/rgen/Microsoft.Macios.Generator/Availability/SymbolAvailabilityBuilder.cs index bc73eaba8a9..e350ee801b4 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/SymbolAvailabilityBuilder.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/SymbolAvailabilityBuilder.cs @@ -90,7 +90,7 @@ internal void AddSupportedVersion (ApplePlatform platform, Version version) if (!supportedPlatforms.Contains (platform)) return; var builder = GetBuilder (platform); - builder.AddSupportedVersion (version); + builder.AddSupportedVersion (new (version, SupportKind.Explicit)); } /// @@ -118,7 +118,7 @@ internal void AddUnsupportedVersion (ApplePlatform platform, Version version, st return; var builder = GetBuilder (platform); - builder.AddUnsupportedVersion (version, message); + builder.AddUnsupportedVersion (new (version, SupportKind.Explicit), message); } /// diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityEqualityTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityEqualityTests.cs index 3d88956ca95..2b833e214f7 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityEqualityTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityEqualityTests.cs @@ -26,8 +26,8 @@ public void EqualSamePlatformDifferentSupportedVersion () { var leftBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.iOS); var rightBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.TVOS); - leftBuilder.AddSupportedVersion (new Version (12, 0)); - rightBuilder.AddSupportedVersion (new Version (10, 0)); + leftBuilder.AddSupportedVersion (new (new Version (12, 0))); + rightBuilder.AddSupportedVersion (new (new Version (10, 0))); var left = leftBuilder.ToImmutable (); var right = rightBuilder.ToImmutable (); Assert.False (left.Equals (right)); @@ -41,7 +41,7 @@ public void EqualsNullSupportedVersion () { var leftBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.iOS); var rightBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.TVOS); - leftBuilder.AddSupportedVersion (new Version (12, 0)); + leftBuilder.AddSupportedVersion (new (new Version (12, 0))); var left = leftBuilder.ToImmutable (); var right = rightBuilder.ToImmutable (); Assert.False (left.Equals (right)); @@ -55,9 +55,9 @@ public void EqualSamePlatformSameSupportedVersionDifferentUnsupportedVersion () { var leftBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.iOS); var rightBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.TVOS); - leftBuilder.AddSupportedVersion (new Version (12, 0)); - leftBuilder.AddUnsupportedVersion (new Version (10, 0), "Unsupported"); - rightBuilder.AddSupportedVersion (new Version (12, 0)); + leftBuilder.AddSupportedVersion (new (new Version (12, 0))); + leftBuilder.AddUnsupportedVersion (new (new Version (10, 0)), "Unsupported"); + rightBuilder.AddSupportedVersion (new (new Version (12, 0))); var left = leftBuilder.ToImmutable (); var right = rightBuilder.ToImmutable (); Assert.False (left.Equals (right)); @@ -71,11 +71,11 @@ public void EqualsSamePlatformSamerSupportedVersionSameUnsupportedDiffObsolete ( { var leftBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.iOS); var rightBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.TVOS); - leftBuilder.AddSupportedVersion (new Version (12, 0)); - leftBuilder.AddUnsupportedVersion (new Version (10, 0), "Unsupported"); + leftBuilder.AddSupportedVersion (new (new Version (12, 0))); + leftBuilder.AddUnsupportedVersion (new (new Version (10, 0)), "Unsupported"); leftBuilder.AddObsoletedVersion (new Version (12, 0), "Obsolete", null); - rightBuilder.AddSupportedVersion (new Version (12, 0)); - rightBuilder.AddUnsupportedVersion (new Version (10, 0), "Unsupported"); + rightBuilder.AddSupportedVersion (new (new Version (12, 0))); + rightBuilder.AddUnsupportedVersion (new (new Version (10, 0)), "Unsupported"); leftBuilder.AddObsoletedVersion (new Version (12, 0), "Obsolete", "url"); var left = leftBuilder.ToImmutable (); var right = rightBuilder.ToImmutable (); diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityMergeTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityMergeTests.cs index af91249c57e..735e33db41f 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityMergeTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityMergeTests.cs @@ -10,15 +10,15 @@ namespace Microsoft.Macios.Generator.Tests.Availability; public class PlatformAvailabilityMergeTests { readonly PlatformAvailability.Builder parentBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.iOS); readonly PlatformAvailability.Builder childBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.iOS); - readonly Version unsupportedPlatform = new Version (); + readonly PlatformSupportVersion unsupportedPlatform = new (new ()); [Fact] public void MergeDifferentPlatforms () { var wrongParentBuilder = PlatformAvailability.CreateBuilder (ApplePlatform.MacOSX); // add data in the child to ensure we do have a real copy - childBuilder.AddSupportedVersion (new Version ()); - childBuilder.AddUnsupportedVersion (new Version (12, 0), "Unsupported version"); + childBuilder.AddSupportedVersion (new (new Version ())); + childBuilder.AddUnsupportedVersion (new (new Version (12, 0)), "Unsupported version"); childBuilder.AddObsoletedVersion (new Version (11, 0), null, null); var child = childBuilder.ToImmutable (); var wrongParent = wrongParentBuilder.ToImmutable (); @@ -34,8 +34,8 @@ public void MergeDifferentPlatforms () public void MergeNullParent () { // add data in the child to ensure we do have a real copy - childBuilder.AddSupportedVersion (new Version ()); - childBuilder.AddUnsupportedVersion (new Version (12, 0), "Unsupported version"); + childBuilder.AddSupportedVersion (new (new Version ())); + childBuilder.AddUnsupportedVersion (new (new Version (12, 0)), "Unsupported version"); childBuilder.AddObsoletedVersion (new Version (11, 0), null, null); var child = childBuilder.ToImmutable (); var merged = child.MergeWithParent (null); @@ -54,13 +54,13 @@ public void MergeWithParentNoParentData () // [UnsupportedOSPlatform ("ios")] // public void Test (); // } - var unsupportedVersion = new Version (12, 0, 0); + var unsupportedVersion = new PlatformSupportVersion (new (12, 0, 0)); childBuilder.AddUnsupportedVersion (unsupportedVersion, "Unsupported version"); var child = childBuilder.ToImmutable (); var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedVersion, merged.UnsupportedVersions); + Assert.Contains (unsupportedVersion.Version, merged.UnsupportedVersions); } [Fact] @@ -77,7 +77,7 @@ public void MergeWithParentUnsupportedParent () var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedPlatform, merged.UnsupportedVersions); + Assert.Contains (unsupportedPlatform.Version, merged.UnsupportedVersions); } [Fact] @@ -90,17 +90,17 @@ public void MergeWithParentUnsupportedAndChildUnsupported () // [UnsupportedOSPlatform ("ios12.0")] // public void Test (); // } - var unsupportedParentVersion = new Version (11, 0, 0); + var unsupportedParentVersion = new PlatformSupportVersion (new (11, 0, 0)); parentBuilder.AddUnsupportedVersion (unsupportedParentVersion, "Unsupported version"); - var unsupportedChildVersion = new Version (12, 0, 0); + var unsupportedChildVersion = new PlatformSupportVersion (new (12, 0, 0)); childBuilder.AddUnsupportedVersion (unsupportedChildVersion, "Unsupported version"); var child = childBuilder.ToImmutable (); var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Equal (2, merged.UnsupportedVersions.Count); // both unsupported versions should appear - Assert.Contains (unsupportedParentVersion, merged.UnsupportedVersions); - Assert.Contains (unsupportedChildVersion, merged.UnsupportedVersions); + Assert.Contains (unsupportedParentVersion.Version, merged.UnsupportedVersions); + Assert.Contains (unsupportedChildVersion.Version, merged.UnsupportedVersions); } [Fact] @@ -114,14 +114,14 @@ public void MergeUnsupportedPlatformParentUnsupportedChildVersion () // public void Test (); // } parentBuilder.AddUnsupportedVersion (unsupportedPlatform, "Unsupported platform"); - var unsupportedChildVersion = new Version (12, 0, 0); + var unsupportedChildVersion = new PlatformSupportVersion (new (12, 0, 0)); childBuilder.AddUnsupportedVersion (unsupportedChildVersion, "Unsupported version"); var child = childBuilder.ToImmutable (); var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedPlatform, merged.UnsupportedVersions); - Assert.DoesNotContain (unsupportedChildVersion, merged.UnsupportedVersions); + Assert.Contains (unsupportedPlatform.Version, merged.UnsupportedVersions); + Assert.DoesNotContain (unsupportedChildVersion.Version, merged.UnsupportedVersions); } [Fact] @@ -134,15 +134,15 @@ public void MergeWithParentUnsupportedVersionUnsupportedPlatformChild () // [UnsupportedOSPlatform ("ios")] // public void Test (); // } - var unsupportedParentVersion = new Version (12, 0, 0); + var unsupportedParentVersion = new PlatformSupportVersion (new (12, 0, 0)); parentBuilder.AddUnsupportedVersion (unsupportedParentVersion, "Unsupported version"); childBuilder.AddUnsupportedVersion (unsupportedPlatform, "Unsupported platform"); var child = childBuilder.ToImmutable (); var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedPlatform, merged.UnsupportedVersions); - Assert.DoesNotContain (unsupportedParentVersion, merged.UnsupportedVersions); + Assert.Contains (unsupportedPlatform.Version, merged.UnsupportedVersions); + Assert.DoesNotContain (unsupportedParentVersion.Version, merged.UnsupportedVersions); } [Fact] @@ -154,16 +154,16 @@ public void MergeWithParentLowerParentVersion () // [SupportedOSPlatform ("ios12.0"] // public void Test (); // } - var supportedParentVersion = new Version (11, 0, 0); + var supportedParentVersion = new PlatformSupportVersion (new (11, 0, 0)); parentBuilder.AddSupportedVersion (supportedParentVersion); - var supportedChildVersion = new Version (12, 0, 0); + var supportedChildVersion = new PlatformSupportVersion (new (12, 0, 0)); childBuilder.AddSupportedVersion (supportedChildVersion); var child = childBuilder.ToImmutable (); var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.NotNull (merged.SupportedVersion); // always pick the most restrictive one - Assert.Equal (supportedChildVersion, merged.SupportedVersion); + Assert.Equal (supportedChildVersion.Version, merged.SupportedVersion); } [Fact] @@ -175,16 +175,16 @@ public void MergeWithParentHigherParentVersion () // [SupportedOSPlatform ("ios11.0"] // public void Test (); // } - var supportedParentVersion = new Version (12, 0, 0); + var supportedParentVersion = new PlatformSupportVersion (new (12, 0, 0)); parentBuilder.AddSupportedVersion (supportedParentVersion); - var supportedChildVersion = new Version (11, 0, 0); + var supportedChildVersion = new PlatformSupportVersion (new (11, 0, 0)); childBuilder.AddSupportedVersion (supportedChildVersion); var child = childBuilder.ToImmutable (); var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.NotNull (merged.SupportedVersion); // always pick the most restrictive one - Assert.Equal (supportedParentVersion, merged.SupportedVersion); + Assert.Equal (supportedParentVersion.Version, merged.SupportedVersion); } [Fact] @@ -196,7 +196,7 @@ public void MergeWithParentUnsupportedChild () // [UnsupportedOSPlatform ("ios"] // public void Test (); // } - var supportedParentVersion = new Version (12, 0, 0); + var supportedParentVersion = new PlatformSupportVersion (new (12, 0, 0)); parentBuilder.AddSupportedVersion (supportedParentVersion); childBuilder.AddUnsupportedVersion (unsupportedPlatform, "Unsupported platform"); var child = childBuilder.ToImmutable (); @@ -214,16 +214,16 @@ public void MergeWithParentUnsupportedParentAndChild () // [UnsupportedOSPlatform ("ios12.0"] // public void Test (); // } - var unsupportedParentVersion = new Version (11, 0, 0); + var unsupportedParentVersion = new PlatformSupportVersion (new (11, 0, 0)); parentBuilder.AddUnsupportedVersion (unsupportedParentVersion, "Unsupported version"); - var unsupportedChildVersion = new Version (12, 0, 0); + var unsupportedChildVersion = new PlatformSupportVersion (new (12, 0, 0)); childBuilder.AddUnsupportedVersion (unsupportedChildVersion, "Unsupported version"); var child = childBuilder.ToImmutable (); var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Equal (2, merged.UnsupportedVersions.Count); - Assert.Contains (unsupportedParentVersion, merged.UnsupportedVersions); - Assert.Contains (unsupportedChildVersion, merged.UnsupportedVersions); + Assert.Contains (unsupportedParentVersion.Version, merged.UnsupportedVersions); + Assert.Contains (unsupportedChildVersion.Version, merged.UnsupportedVersions); } [Fact] @@ -235,13 +235,13 @@ public void MergeWithParentUnsupportedEmptyChild () // // public void Test (); // } - var unsupportedParentVersion = new Version (11, 0, 0); + var unsupportedParentVersion = new PlatformSupportVersion (new (11, 0, 0)); parentBuilder.AddUnsupportedVersion (unsupportedParentVersion, "Unsupported platform"); var child = childBuilder.ToImmutable (); var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedParentVersion, merged.UnsupportedVersions); + Assert.Contains (unsupportedParentVersion.Version, merged.UnsupportedVersions); } [Fact] @@ -255,14 +255,14 @@ public void MergeWithUnsupportedParentChildSameVersion () // public void Test (); // } var childMsg = "This was an error."; - var unsupportedParentVersion = new Version (11, 0, 0); + var unsupportedParentVersion = new PlatformSupportVersion (new (11, 0, 0)); parentBuilder.AddUnsupportedVersion (unsupportedParentVersion, null); childBuilder.AddUnsupportedVersion (unsupportedParentVersion, childMsg); var child = childBuilder.ToImmutable (); var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedParentVersion, merged.UnsupportedVersions); - Assert.Equal (childMsg, merged.UnsupportedVersions [unsupportedParentVersion]); + Assert.Contains (unsupportedParentVersion.Version, merged.UnsupportedVersions); + Assert.Equal (childMsg, merged.UnsupportedVersions [unsupportedParentVersion.Version]); } } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityToStringTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityToStringTests.cs index 1072fd9fca2..b0236e4ffdf 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityToStringTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityToStringTests.cs @@ -21,20 +21,20 @@ public IEnumerator GetEnumerator () yield return [builder.ToImmutable (), "{ Platform: 'iOS', Supported: '', Unsupported: [], Obsoleted: [] }"]; builder.Clear (); - builder.AddSupportedVersion (new Version (16, 0)); + builder.AddSupportedVersion (new (new Version (16, 0))); yield return [builder.ToImmutable (), "{ Platform: 'iOS', Supported: '16.0', Unsupported: [], Obsoleted: [] }"]; builder.Clear (); - builder.AddUnsupportedVersion (new Version (16, 0), null); + builder.AddUnsupportedVersion (new (new Version (16, 0)), null); yield return [builder.ToImmutable (), "{ Platform: 'iOS', Supported: '', Unsupported: ['16.0': 'null'], Obsoleted: [] }"]; builder.Clear (); - builder.AddUnsupportedVersion (new Version (16, 0), "Not supported."); + builder.AddUnsupportedVersion (new (new Version (16, 0)), "Not supported."); yield return [builder.ToImmutable (), "{ Platform: 'iOS', Supported: '', Unsupported: ['16.0': 'Not supported.'], Obsoleted: [] }"]; builder.Clear (); - builder.AddUnsupportedVersion (new Version (16, 0), "Not supported."); - builder.AddUnsupportedVersion (new Version (18, 0), "Not supported."); + builder.AddUnsupportedVersion (new (new Version (16, 0)), "Not supported."); + builder.AddUnsupportedVersion (new (new Version (18, 0)), "Not supported."); yield return [builder.ToImmutable (), "{ Platform: 'iOS', Supported: '', Unsupported: ['16.0': 'Not supported.', '18.0': 'Not supported.'], Obsoleted: [] }"]; builder.Clear (); @@ -55,9 +55,9 @@ public IEnumerator GetEnumerator () yield return [builder.ToImmutable (), "{ Platform: 'iOS', Supported: '', Unsupported: [], Obsoleted: ['16.0': ('Obsoleted method', 'https://bing.com'), '18.0': ('Obsoleted method', 'https://bing.com')] }"]; builder.Clear (); - builder.AddSupportedVersion (new Version (16, 0)); - builder.AddUnsupportedVersion (new Version (16, 0), "Not supported."); - builder.AddUnsupportedVersion (new Version (18, 0), "Not supported."); + builder.AddSupportedVersion (new (new Version (16, 0))); + builder.AddUnsupportedVersion (new (new Version (16, 0)), "Not supported."); + builder.AddUnsupportedVersion (new (new Version (18, 0)), "Not supported."); builder.AddObsoletedVersion (new Version (16, 0), "Obsoleted method", "https://bing.com"); builder.AddObsoletedVersion (new Version (18, 0), "Obsoleted method", "https://bing.com"); yield return [builder.ToImmutable (), "{ Platform: 'iOS', Supported: '16.0', Unsupported: ['16.0': 'Not supported.', '18.0': 'Not supported.'], Obsoleted: ['16.0': ('Obsoleted method', 'https://bing.com'), '18.0': ('Obsoleted method', 'https://bing.com')] }"]; From ec61da7d071acc137828fcc7dbaf2ac5803223ca Mon Sep 17 00:00:00 2001 From: GitHub Actions Autoformatter Date: Wed, 17 Sep 2025 21:12:53 +0000 Subject: [PATCH 4/6] Auto-format source code --- .../Availability/PlatformAvailabilityBuilder.cs | 8 ++++---- .../Availability/PlatformSupportVersion.cs | 4 ++-- .../Availability/PlatformSupportVersionComparer.cs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs index 7d05c093ca6..0efec49d99f 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs @@ -44,8 +44,8 @@ internal void AddSupportedVersion (PlatformSupportVersion version) return; // update the supported version to the larges of the two - supportedVersion = supportedVersion is null - ? version + supportedVersion = supportedVersion is null + ? version : PlatformSupportVersion.Max (version, supportedVersion.Value); } @@ -59,7 +59,7 @@ public void Add (SupportedOSPlatformData supportedPlatform) if (supportedPlatform.Platform != platform) return; // no version is present, therefore try to set the default one - AddSupportedVersion ( new (supportedPlatform.Version, SupportKind.Explicit)); + AddSupportedVersion (new (supportedPlatform.Version, SupportKind.Explicit)); } /// @@ -85,7 +85,7 @@ internal void AddUnsupportedVersion (PlatformSupportVersion version, string? mes // that we did not fully unsupported the platform, if that is the case, we ignore this version if (unsupported.ContainsKey (PlatformSupportVersion.ExplicitDefault)) return; - + // we implicitly unsupported the platform, remove that entry since we are adding a version unsupported.Remove (PlatformSupportVersion.ImplicitDefault); unsupported [version] = message; diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs index 5dc2421f5e4..e6966fd4cb5 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs @@ -44,12 +44,12 @@ public PlatformSupportVersion (Version version, SupportKind kind) Version = version; Kind = kind; } - + /// /// Initializes a new instance of the struct with an explicit support kind. /// /// The version number. - public PlatformSupportVersion (Version version) : this(version, SupportKind.Explicit) {} + public PlatformSupportVersion (Version version) : this (version, SupportKind.Explicit) { } /// /// Returns the platform support version with the highest precedence. diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersionComparer.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersionComparer.cs index 33f52f300ac..63efef36422 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersionComparer.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersionComparer.cs @@ -9,17 +9,17 @@ namespace Microsoft.Macios.Generator.Availability; /// Compares two instances for sorting. /// public class PlatformSupportVersionComparer : IComparer { - + /// /// Compares two platform support versions and returns a value indicating whether one is less than, equal to, or greater than the other. /// /// The first object to compare. /// The second object to compare. /// A signed integer that indicates the relative values of x and y. - public int Compare(PlatformSupportVersion x, PlatformSupportVersion y) + public int Compare (PlatformSupportVersion x, PlatformSupportVersion y) { - int versionComparison = x.Version.CompareTo(y.Version); + int versionComparison = x.Version.CompareTo (y.Version); if (versionComparison != 0) return versionComparison; - return x.Kind.CompareTo(y.Kind); + return x.Kind.CompareTo (y.Kind); } } From ef4495857ffbf36e6dcc71d860607edcb4a9e1d7 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Saenz Date: Thu, 18 Sep 2025 06:58:55 -0400 Subject: [PATCH 5/6] [RGen] Use the PlatformSupportVersion for the supported and unsupported versions. This commit has not behaviour change yet, we are keeping the same behaviour but we are using the PlatformSupportVersion to later be able to perform better decisions for situations such as: ``` pulib class Test { [SupportedOSPlatform ("ios")] pulic int Count { get; set; } ``` By using PlatformSupportVersion we will be able to check that Count is only supported on iOS because the attr was added and its addition to the other platforms was implicit. The decision making will be added in comming PRs. --- .../Availability/PlatformAvailability.cs | 32 ++++---- .../PlatformAvailabilityBuilder.cs | 6 +- .../Availability/PlatformSupportVersion.cs | 80 ++++++++++++++++--- .../IO/TabbedStringBuilderAvailability.cs | 12 +-- .../PlatformAvailabilityMergeTests.cs | 30 +++---- .../Availability/PlatformAvailabilityTests.cs | 40 +++++----- 6 files changed, 130 insertions(+), 70 deletions(-) diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs index 075951107a3..22f6a05f56d 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs @@ -29,14 +29,14 @@ namespace Microsoft.Macios.Generator.Availability; /// The supported version of the platform. If null, that means that the user did not add a SupportedOSPlatform /// attribute. /// - public Version? SupportedVersion { get; } + public PlatformSupportVersion? SupportedVersion { get; } - readonly SortedDictionary unsupported = new (); + readonly SortedDictionary unsupported = new (); /// /// Dictionary that contains all the obsoleted versions and their optional data. /// - public IReadOnlyDictionary UnsupportedVersions => unsupported; + public IReadOnlyDictionary UnsupportedVersions => unsupported; readonly SortedDictionary obsoleted = new (); @@ -53,11 +53,12 @@ public bool IsSupported { // a platform is supported if: // 1. The supported version is not null, either the default version or a specific one // 2. The default version is not in the unsupported list - return SupportedVersion is not null && !unsupported.ContainsKey (defaultVersion); + return SupportedVersion is not null + && !unsupported.ContainsKey (PlatformSupportVersion.ImplicitDefault) + && !unsupported.ContainsKey (PlatformSupportVersion.ExplicitDefault); } } - /// /// Returns if a version is the default version. /// @@ -65,9 +66,8 @@ public bool IsSupported { /// True if the version is default. public static bool IsDefaultVersion (Version version) => version == defaultVersion; - - PlatformAvailability (ApplePlatform platform, Version? supportedVersion, - SortedDictionary unsupportedVersions, + PlatformAvailability (ApplePlatform platform, PlatformSupportVersion? supportedVersion, + SortedDictionary unsupportedVersions, SortedDictionary obsoletedVersions) { Platform = platform; @@ -116,21 +116,19 @@ public PlatformAvailability MergeWithParent (PlatformAvailability? parent) // 1. If the parent has unsupported versions we will add them to the merge. If the kid has them, we will // add them too foreach (var (version, message) in parent.Value.unsupported) { - builder.AddUnsupportedVersion (new (version, SupportKind.Explicit), message); + builder.AddUnsupportedVersion (version, message); } foreach (var (version, message) in unsupported) { - builder.AddUnsupportedVersion (new (version, SupportKind.Explicit), message); + builder.AddUnsupportedVersion (version, message); } // 2. if supported in the platform, we will always pick the larges version between // the two. Now, because we might be unsupported - var supportedVersion = (parent.Value.SupportedVersion > SupportedVersion) - ? parent.Value.SupportedVersion - : SupportedVersion; + var supportedVersion = PlatformSupportVersion.Max (parent.Value.SupportedVersion, SupportedVersion); if (supportedVersion is not null) - builder.AddSupportedVersion (new (supportedVersion, SupportKind.Explicit)); + builder.AddSupportedVersion (supportedVersion.Value); // similar to the unsupported versions, if the parent has obsolete ones, we will add them foreach (var (version, obsoleteInfo) in parent.Value.obsoleted) { @@ -148,7 +146,7 @@ public PlatformAvailability MergeWithParent (PlatformAvailability? parent) public bool Equals (PlatformAvailability other) { var obsoleteComparer = new DictionaryComparer (); - var unsupportedComparer = new DictionaryComparer (); + var unsupportedComparer = new DictionaryComparer (); var x = Equals (SupportedVersion, other.SupportedVersion); return Platform == other.Platform && @@ -184,9 +182,9 @@ public override string ToString () { var sb = new StringBuilder ("{ "); sb.Append ($"Platform: '{Platform}', "); - sb.Append ($"Supported: '{SupportedVersion?.ToString ()}', "); + sb.Append ($"Supported: '{SupportedVersion?.Version.ToString ()}', "); sb.Append ("Unsupported: ["); - sb.AppendJoin (", ", unsupported.Select (v => $"'{v.Key}': '{v.Value?.ToString () ?? "null"}'")); + sb.AppendJoin (", ", unsupported.Select (v => $"'{v.Key.Version}': '{v.Value?.ToString () ?? "null"}'")); sb.Append ("], Obsoleted: ["); sb.AppendJoin (", ", obsoleted.Select (v => $"'{v.Key}': ('{v.Value.Message?.ToString () ?? "null"}', '{v.Value.Url?.ToString () ?? "null"}')")); sb.Append ("] }"); diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs index 0efec49d99f..db909c7896b 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailabilityBuilder.cs @@ -142,11 +142,7 @@ public void Add (ObsoletedOSPlatformData obsoletedPlatform) /// A new readonly structure that contains the platform availability. public PlatformAvailability ToImmutable () { - var unsupportedCopy = new SortedDictionary (); - foreach (var (version, message) in unsupported) { - unsupportedCopy.Add (version.Version, message); - } - return new PlatformAvailability (platform, supportedVersion?.Version, unsupportedCopy, obsoleted); + return new PlatformAvailability (platform, supportedVersion, unsupported, obsoleted); } /// diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs index e6966fd4cb5..b05ad1c270e 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs @@ -8,7 +8,7 @@ namespace Microsoft.Macios.Generator.Availability; /// /// Represents a platform support version, combining a version number and a support kind. /// -public readonly record struct PlatformSupportVersion { +public readonly record struct PlatformSupportVersion : IComparable { /// /// Gets the version number. /// @@ -60,12 +60,17 @@ public PlatformSupportVersion (Version version) : this (version, SupportKind.Exp /// The platform support version with the highest precedence. If the kinds are the same, it returns the one with the greater version. /// If the kinds are different, it returns the one with the higher kind value. /// - public static PlatformSupportVersion Max (PlatformSupportVersion v1, PlatformSupportVersion v2) + public static PlatformSupportVersion? Max (PlatformSupportVersion? v1, PlatformSupportVersion? v2) { - if (v1.Kind == v2.Kind) { - return v1.Version >= v2.Version ? v1 : v2; + if (v1 is null) + return v2; + if (v2 is null) + return v1; + + if (v1.Value.Kind == v2.Value.Kind) { + return v1.Value.Version >= v2.Value.Version ? v1 : v2; } - return (int) v1.Kind > (int) v2.Kind ? v1 : v2; + return (int) v1.Value.Kind > (int) v2.Value.Kind ? v1 : v2; } /// @@ -77,11 +82,68 @@ public static PlatformSupportVersion Max (PlatformSupportVersion v1, PlatformSup /// The platform support version with the lowest version if the kinds are the same. /// If the kinds are different, it returns the one with the higher kind value. /// - public static PlatformSupportVersion Min (PlatformSupportVersion v1, PlatformSupportVersion v2) + public static PlatformSupportVersion? Min (PlatformSupportVersion? v1, PlatformSupportVersion? v2) { - if (v1.Kind == v2.Kind) { - return v1.Version <= v2.Version ? v1 : v2; + if (v1 is null) + return v2; + if (v2 is null) + return v1; + if (v1.Value.Kind == v2.Value.Kind) { + return v1.Value.Version <= v2.Value.Version ? v1 : v2; } - return (int) v1.Kind > (int) v2.Kind ? v1 : v2; + return (int) v1.Value.Kind > (int) v2.Value.Kind ? v1 : v2; + } + + /// + public int CompareTo(PlatformSupportVersion other) + { + var versionComparison = Version.CompareTo (other.Version); + if (versionComparison != 0) + return versionComparison; + return Kind.CompareTo (other.Kind); + } + + /// + /// Compares two instances to determine if the left is less than the right. + /// + /// The first to compare. + /// The second to compare. + /// true if the left instance is less than the right instance; otherwise, false. + public static bool operator <(PlatformSupportVersion left, PlatformSupportVersion right) + { + return left.CompareTo (right) < 0; + } + + /// + /// Compares two instances to determine if the left is greater than the right. + /// + /// The first to compare. + /// The second to compare. + /// true if the left instance is greater than the right instance; otherwise, false. + public static bool operator >(PlatformSupportVersion left, PlatformSupportVersion right) + { + return left.CompareTo (right) > 0; + } + + /// + /// Compares two instances to determine if the left is less than or equal to the right. + /// + /// The first to compare. + /// The second to compare. + /// true if the left instance is less than or equal to the right instance; otherwise, false. + public static bool operator <=(PlatformSupportVersion left, PlatformSupportVersion right) + { + return left.CompareTo (right) <= 0; + } + + /// + /// Compares two instances to determine if the left is greater than or equal to the right. + /// + /// The first to compare. + /// The second to compare. + /// true if the left instance is greater than or equal to the right instance; otherwise, false. + public static bool operator >=(PlatformSupportVersion left, PlatformSupportVersion right) + { + return left.CompareTo(right) >= 0; } } diff --git a/src/rgen/Microsoft.Macios.Generator/IO/TabbedStringBuilderAvailability.cs b/src/rgen/Microsoft.Macios.Generator/IO/TabbedStringBuilderAvailability.cs index f3d6732c15a..9870b04abd9 100644 --- a/src/rgen/Microsoft.Macios.Generator/IO/TabbedStringBuilderAvailability.cs +++ b/src/rgen/Microsoft.Macios.Generator/IO/TabbedStringBuilderAvailability.cs @@ -15,15 +15,15 @@ public static TabbedWriter AppendMemberAvailability (this TabbedWr foreach (var availability in allPlatformsAvailability.PlatformAvailabilities) { var platformName = availability.Platform.AsString ().ToLower (); if (availability.SupportedVersion is not null) { - var versionStr = (PlatformAvailability.IsDefaultVersion (availability.SupportedVersion)) + var versionStr = (PlatformAvailability.IsDefaultVersion (availability.SupportedVersion.Value.Version)) ? string.Empty - : availability.SupportedVersion.ToString (); + : availability.SupportedVersion.Value.Version.ToString (); self.WriteLine ($"[SupportedOSPlatform (\"{platformName}{versionStr}\")]"); } // loop over the unsupported versions of the platform foreach (var (version, message) in availability.UnsupportedVersions) { - var versionStr = (PlatformAvailability.IsDefaultVersion (version)) ? string.Empty : version.ToString (); + var versionStr = (PlatformAvailability.IsDefaultVersion (version.Version)) ? string.Empty : version.Version.ToString (); if (message is null) { self.WriteLine ($"[UnsupportedOSPlatform (\"{platformName}{versionStr}\")]"); } else { @@ -61,15 +61,15 @@ public static async Task> AppendMemberAvailabilityAsy foreach (var availability in allPlatformsAvailability.PlatformAvailabilities) { var platformName = availability.Platform.AsString ().ToLower (); if (availability.SupportedVersion is not null) { - var versionStr = (PlatformAvailability.IsDefaultVersion (availability.SupportedVersion)) + var versionStr = (PlatformAvailability.IsDefaultVersion (availability.SupportedVersion.Value.Version)) ? string.Empty - : availability.SupportedVersion.ToString (); + : availability.SupportedVersion.Value.Version.ToString (); await self.WriteLineAsync ($"[SupportedOSPlatform (\"{platformName}{versionStr}\")]"); } // loop over the unsupported versions of the platform foreach (var (version, message) in availability.UnsupportedVersions) { - var versionStr = (PlatformAvailability.IsDefaultVersion (version)) ? string.Empty : version.ToString (); + var versionStr = (PlatformAvailability.IsDefaultVersion (version.Version)) ? string.Empty : version.Version.ToString (); if (message is null) { await self.WriteLineAsync ($"[UnsupportedOSPlatform (\"{platformName}{versionStr}\")]"); } else { diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityMergeTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityMergeTests.cs index 735e33db41f..fd941e77da7 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityMergeTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityMergeTests.cs @@ -60,7 +60,7 @@ public void MergeWithParentNoParentData () var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedVersion.Version, merged.UnsupportedVersions); + Assert.Contains (unsupportedVersion, merged.UnsupportedVersions); } [Fact] @@ -77,7 +77,7 @@ public void MergeWithParentUnsupportedParent () var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedPlatform.Version, merged.UnsupportedVersions); + Assert.Contains (unsupportedPlatform, merged.UnsupportedVersions); } [Fact] @@ -99,8 +99,8 @@ public void MergeWithParentUnsupportedAndChildUnsupported () var merged = child.MergeWithParent (parent); Assert.Equal (2, merged.UnsupportedVersions.Count); // both unsupported versions should appear - Assert.Contains (unsupportedParentVersion.Version, merged.UnsupportedVersions); - Assert.Contains (unsupportedChildVersion.Version, merged.UnsupportedVersions); + Assert.Contains (unsupportedParentVersion, merged.UnsupportedVersions); + Assert.Contains (unsupportedChildVersion, merged.UnsupportedVersions); } [Fact] @@ -120,8 +120,8 @@ public void MergeUnsupportedPlatformParentUnsupportedChildVersion () var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedPlatform.Version, merged.UnsupportedVersions); - Assert.DoesNotContain (unsupportedChildVersion.Version, merged.UnsupportedVersions); + Assert.Contains (unsupportedPlatform, merged.UnsupportedVersions); + Assert.DoesNotContain (unsupportedChildVersion, merged.UnsupportedVersions); } [Fact] @@ -141,8 +141,8 @@ public void MergeWithParentUnsupportedVersionUnsupportedPlatformChild () var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedPlatform.Version, merged.UnsupportedVersions); - Assert.DoesNotContain (unsupportedParentVersion.Version, merged.UnsupportedVersions); + Assert.Contains (unsupportedPlatform, merged.UnsupportedVersions); + Assert.DoesNotContain (unsupportedParentVersion, merged.UnsupportedVersions); } [Fact] @@ -163,7 +163,7 @@ public void MergeWithParentLowerParentVersion () var merged = child.MergeWithParent (parent); Assert.NotNull (merged.SupportedVersion); // always pick the most restrictive one - Assert.Equal (supportedChildVersion.Version, merged.SupportedVersion); + Assert.Equal (supportedChildVersion, merged.SupportedVersion); } [Fact] @@ -184,7 +184,7 @@ public void MergeWithParentHigherParentVersion () var merged = child.MergeWithParent (parent); Assert.NotNull (merged.SupportedVersion); // always pick the most restrictive one - Assert.Equal (supportedParentVersion.Version, merged.SupportedVersion); + Assert.Equal (supportedParentVersion, merged.SupportedVersion); } [Fact] @@ -222,8 +222,8 @@ public void MergeWithParentUnsupportedParentAndChild () var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Equal (2, merged.UnsupportedVersions.Count); - Assert.Contains (unsupportedParentVersion.Version, merged.UnsupportedVersions); - Assert.Contains (unsupportedChildVersion.Version, merged.UnsupportedVersions); + Assert.Contains (unsupportedParentVersion, merged.UnsupportedVersions); + Assert.Contains (unsupportedChildVersion, merged.UnsupportedVersions); } [Fact] @@ -241,7 +241,7 @@ public void MergeWithParentUnsupportedEmptyChild () var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedParentVersion.Version, merged.UnsupportedVersions); + Assert.Contains (unsupportedParentVersion, merged.UnsupportedVersions); } [Fact] @@ -262,7 +262,7 @@ public void MergeWithUnsupportedParentChildSameVersion () var parent = parentBuilder.ToImmutable (); var merged = child.MergeWithParent (parent); Assert.Single (merged.UnsupportedVersions); - Assert.Contains (unsupportedParentVersion.Version, merged.UnsupportedVersions); - Assert.Equal (childMsg, merged.UnsupportedVersions [unsupportedParentVersion.Version]); + Assert.Contains (unsupportedParentVersion, merged.UnsupportedVersions); + Assert.Equal (childMsg, merged.UnsupportedVersions [unsupportedParentVersion]); } } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityTests.cs index 9b4a78eeec1..706b2933fee 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityTests.cs @@ -22,7 +22,8 @@ public void SupportPlatform (ApplePlatform platform, string attributePlatformNam var attrData = new SupportedOSPlatformData (attributePlatformName); builder.Add (attrData); var availability = builder.ToImmutable (); - Assert.Equal (availability.SupportedVersion, new Version ()); + Assert.NotNull (availability.SupportedVersion); + Assert.Equal (availability.SupportedVersion.Value.Version, new Version ()); } [Theory] @@ -52,7 +53,8 @@ public void SupportPlatformWithPlatformAttributeWithVersion (ApplePlatform platf builder.Add (attrData); var expectedVersion = Version.Parse (version); var availability = builder.ToImmutable (); - Assert.Equal (expectedVersion, availability.SupportedVersion); + Assert.NotNull (availability.SupportedVersion); + Assert.Equal (expectedVersion, availability.SupportedVersion.Value.Version); } [Theory] @@ -73,7 +75,8 @@ public void SupportPlatformAndThenAddHigherVersion (ApplePlatform platform, stri var expectedVersion = Version.Parse (version); // should be most specific version var availability = builder.ToImmutable (); - Assert.Equal (expectedVersion, availability.SupportedVersion); + Assert.NotNull (availability.SupportedVersion); + Assert.Equal (expectedVersion, availability.SupportedVersion.Value.Version); } [Theory] @@ -94,7 +97,8 @@ public void SupportPlatformSeveralVersionsPickHigherVersion (ApplePlatform platf var expected = Version.Parse (expectedVersion); var availability = builder.ToImmutable (); - Assert.Equal (expected, availability.SupportedVersion); + Assert.NotNull (availability.SupportedVersion); + Assert.Equal (expected, availability.SupportedVersion.Value.Version); } [Theory] @@ -107,11 +111,10 @@ public void UnsupportPlatform (ApplePlatform platform, string attributePlatformN var builder = PlatformAvailability.CreateBuilder (platform); var attrData = new UnsupportedOSPlatformData (attributePlatformName); builder.Add (attrData); - var defaultVersion = new Version (); var availability = builder.ToImmutable (); - Assert.Contains (defaultVersion, availability.UnsupportedVersions.Keys); + Assert.Contains (PlatformSupportVersion.ExplicitDefault, availability.UnsupportedVersions.Keys); Assert.Single (availability.UnsupportedVersions); - Assert.Null (availability.UnsupportedVersions [defaultVersion]); + Assert.Null (availability.UnsupportedVersions [PlatformSupportVersion.ExplicitDefault]); } [Theory] @@ -124,11 +127,10 @@ public void UnsupportPlatformWithMessage (ApplePlatform platform, string attribu var builder = PlatformAvailability.CreateBuilder (platform); var attrData = new UnsupportedOSPlatformData (attributePlatformName, message); builder.Add (attrData); - var defaultVersion = new Version (); var availability = builder.ToImmutable (); - Assert.Contains (defaultVersion, availability.UnsupportedVersions.Keys); + Assert.Contains (PlatformSupportVersion.ExplicitDefault, availability.UnsupportedVersions.Keys); Assert.Single (availability.UnsupportedVersions); - Assert.Equal (message, availability.UnsupportedVersions [defaultVersion]); + Assert.Equal (message, availability.UnsupportedVersions [PlatformSupportVersion.ExplicitDefault]); } [Theory] @@ -145,11 +147,10 @@ public void UnsupportVersionAndPlatform (ApplePlatform platform, string attribut var platformAttrData = new UnsupportedOSPlatformData (platform.AsString ().ToLower (), message); builder.Add (versionAttrData); builder.Add (platformAttrData); - var defaultVersion = new Version (); var availability = builder.ToImmutable (); - Assert.Contains (defaultVersion, availability.UnsupportedVersions.Keys); + Assert.Contains (PlatformSupportVersion.ExplicitDefault, availability.UnsupportedVersions.Keys); Assert.Single (availability.UnsupportedVersions); - Assert.Equal (message, availability.UnsupportedVersions [defaultVersion]); + Assert.Equal (message, availability.UnsupportedVersions [PlatformSupportVersion.ExplicitDefault]); } [Theory] @@ -182,8 +183,8 @@ public void SupportAndUnsupportPlatform (ApplePlatform platform, string? message var availability = builder.ToImmutable (); Assert.Null (availability.SupportedVersion); Assert.Single (availability.UnsupportedVersions); - Assert.Contains (new Version (), availability.UnsupportedVersions.Keys); - Assert.Equal (message, availability.UnsupportedVersions [new Version ()]); + Assert.Contains (PlatformSupportVersion.ExplicitDefault, availability.UnsupportedVersions.Keys); + Assert.Equal (message, availability.UnsupportedVersions [PlatformSupportVersion.ExplicitDefault]); } [Theory] @@ -213,8 +214,8 @@ public void UnsupportSeveralVersionAndPlatform (ApplePlatform platform, string [ var availability = builder.ToImmutable (); Assert.Single (availability.UnsupportedVersions); - Assert.Contains (new Version (), availability.UnsupportedVersions.Keys); - Assert.Equal (message, availability.UnsupportedVersions [new Version ()]); + Assert.Contains (PlatformSupportVersion.ExplicitDefault, availability.UnsupportedVersions.Keys); + Assert.Equal (message, availability.UnsupportedVersions [PlatformSupportVersion.ExplicitDefault]); } [Theory] @@ -239,10 +240,13 @@ public void UnsupportedSeveralVersions (ApplePlatform platform, string [] versio } var availability = builder.ToImmutable (); + // get all the versions we added + var unsupported= availability.UnsupportedVersions.Keys + .Select (x => x.Version).ToArray (); // assert that the version is present foreach (var v in versions) { var currentVersion = Version.Parse (v); - Assert.Contains (currentVersion, availability.UnsupportedVersions.Keys); + Assert.Contains (currentVersion, unsupported); } } From 47f3c284c2609e3132fd6e2bbfab6ad1e2834a79 Mon Sep 17 00:00:00 2001 From: GitHub Actions Autoformatter Date: Thu, 18 Sep 2025 11:07:05 +0000 Subject: [PATCH 6/6] Auto-format source code --- .../Availability/PlatformAvailability.cs | 4 ++-- .../Availability/PlatformSupportVersion.cs | 12 ++++++------ .../Availability/PlatformAvailabilityTests.cs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs index 22f6a05f56d..8d2b060fffb 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformAvailability.cs @@ -54,8 +54,8 @@ public bool IsSupported { // 1. The supported version is not null, either the default version or a specific one // 2. The default version is not in the unsupported list return SupportedVersion is not null - && !unsupported.ContainsKey (PlatformSupportVersion.ImplicitDefault) - && !unsupported.ContainsKey (PlatformSupportVersion.ExplicitDefault); + && !unsupported.ContainsKey (PlatformSupportVersion.ImplicitDefault) + && !unsupported.ContainsKey (PlatformSupportVersion.ExplicitDefault); } } diff --git a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs index b05ad1c270e..c79100c2e93 100644 --- a/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs +++ b/src/rgen/Microsoft.Macios.Generator/Availability/PlatformSupportVersion.cs @@ -95,7 +95,7 @@ public PlatformSupportVersion (Version version) : this (version, SupportKind.Exp } /// - public int CompareTo(PlatformSupportVersion other) + public int CompareTo (PlatformSupportVersion other) { var versionComparison = Version.CompareTo (other.Version); if (versionComparison != 0) @@ -109,7 +109,7 @@ public int CompareTo(PlatformSupportVersion other) /// The first to compare. /// The second to compare. /// true if the left instance is less than the right instance; otherwise, false. - public static bool operator <(PlatformSupportVersion left, PlatformSupportVersion right) + public static bool operator < (PlatformSupportVersion left, PlatformSupportVersion right) { return left.CompareTo (right) < 0; } @@ -120,7 +120,7 @@ public int CompareTo(PlatformSupportVersion other) /// The first to compare. /// The second to compare. /// true if the left instance is greater than the right instance; otherwise, false. - public static bool operator >(PlatformSupportVersion left, PlatformSupportVersion right) + public static bool operator > (PlatformSupportVersion left, PlatformSupportVersion right) { return left.CompareTo (right) > 0; } @@ -131,7 +131,7 @@ public int CompareTo(PlatformSupportVersion other) /// The first to compare. /// The second to compare. /// true if the left instance is less than or equal to the right instance; otherwise, false. - public static bool operator <=(PlatformSupportVersion left, PlatformSupportVersion right) + public static bool operator <= (PlatformSupportVersion left, PlatformSupportVersion right) { return left.CompareTo (right) <= 0; } @@ -142,8 +142,8 @@ public int CompareTo(PlatformSupportVersion other) /// The first to compare. /// The second to compare. /// true if the left instance is greater than or equal to the right instance; otherwise, false. - public static bool operator >=(PlatformSupportVersion left, PlatformSupportVersion right) + public static bool operator >= (PlatformSupportVersion left, PlatformSupportVersion right) { - return left.CompareTo(right) >= 0; + return left.CompareTo (right) >= 0; } } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityTests.cs index 706b2933fee..d8863d65b96 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Availability/PlatformAvailabilityTests.cs @@ -241,7 +241,7 @@ public void UnsupportedSeveralVersions (ApplePlatform platform, string [] versio var availability = builder.ToImmutable (); // get all the versions we added - var unsupported= availability.UnsupportedVersions.Keys + var unsupported = availability.UnsupportedVersions.Keys .Select (x => x.Version).ToArray (); // assert that the version is present foreach (var v in versions) {