Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Closed
103 changes: 68 additions & 35 deletions Microsoft.Toolkit.Uwp.PlatformSpecificAnalyzer/Analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,52 @@ internal enum TypePresenceIndicator

private static Dictionary<string, Dictionary<string, List<NewMember>>> _differencesDictionary = null;

/*
* SDK vs API Version
* 10240 1.0.0.0
* 10586 2.0.0.0
* 14393 3.0.0.0
* 15063 4.0.0.0
* 16299 5.0.0.0
* 17134 6.0.0.0
* 17763 7.0.0.0
* 18362 8.0.0.0
*/

/// <summary>
/// Embedded differences between API contract version 4 and 5.
/// Embedded differences between API contract version 5 and 6.
/// </summary>
public const string N1DifferencesRes = "Differences-5.0.0.0.gz";
public const string N2DifferencesRes = "Differences-6.0.0.0.gz";

Comment thread
hermitdave marked this conversation as resolved.
Resolved
/// <summary>
/// Embedded differences between API contract version 5 and 6.
/// Embedded differences between API contract version 6 and 7.
/// </summary>
public const string N0DifferencesRes = "Differences-6.0.0.0.gz";
public const string N1DifferencesRes = "Differences-7.0.0.0.gz";

/// <summary>
/// Embedded differences between API contract version 7 and 8.
/// </summary>
public const string N0DifferencesRes = "Differences-8.0.0.0.gz";

/// <summary>
/// Earliest supported SDK version.
/// </summary>
public const string N2SDKVersion = "15063";
public const string BaseSDKVersion = "16299";

/// <summary>
/// Earliest supported SDK version.
/// </summary>
public const string N2SDKVersion = "17134";

/// <summary>
/// Intermediate SDK version.
/// </summary>
public const string N1SDKVersion = "16299";
public const string N1SDKVersion = "17763";

/// <summary>
/// Latest SDK version.
/// </summary>
public const string N0SDKVersion = "17134";
public const string N0SDKVersion = "18362";

/// <summary>
/// Platform related diagnostic descriptor
Expand Down Expand Up @@ -161,7 +183,7 @@ public static Platform GetPlatformForSymbol(ISymbol symbol)
// Any call to ApiInformation.* is allowed without warning
if (symbol.ContainingType?.Name == "ApiInformation")
{
return new Platform(PlatformKind.Uwp, Analyzer.N2SDKVersion);
return new Platform(PlatformKind.Uwp, Analyzer.BaseSDKVersion);
}

// Don't want to give warning when analyzing code in an PCL project.
Expand All @@ -174,13 +196,13 @@ public static Platform GetPlatformForSymbol(ISymbol symbol)
// Some WinRT types like Windows.UI.Color get projected to come from .NET assemblies, always present:
if (assembly.StartsWith("System.Runtime."))
{
return new Platform(PlatformKind.Uwp, Analyzer.N2SDKVersion);
return new Platform(PlatformKind.Uwp, Analyzer.BaseSDKVersion);
}

// Some things are emphatically part of UWP.10240
if (assembly == "Windows.Foundation.FoundationContract" || (assembly == "Windows.Foundation.UniversalApiContract" && version == 1))
{
return new Platform(PlatformKind.Uwp, Analyzer.N2SDKVersion);
return new Platform(PlatformKind.Uwp, Analyzer.BaseSDKVersion);
}

if (assembly == "Windows.Foundation.UniversalApiContract")
Expand All @@ -189,38 +211,28 @@ public static Platform GetPlatformForSymbol(ISymbol symbol)

var typeName = isType ? symbol.ToDisplayString() : symbol.ContainingType.ToDisplayString();

TypePresenceIndicator presentInN0ApiDiff = CheckCollectionForType(Analyzer.GetUniversalApiAdditions(Analyzer.N0DifferencesRes), typeName, symbol);
var platformN0 = GetPlatformFromDifferences(symbol, typeName, N0DifferencesRes, N0SDKVersion);

if (presentInN0ApiDiff == TypePresenceIndicator.New)
if (!string.IsNullOrEmpty(platformN0.Version))
{
// the entire type was found in Target Version
return new Platform(PlatformKind.Uwp, Analyzer.N0SDKVersion);
return platformN0;
}
else if (presentInN0ApiDiff == TypePresenceIndicator.Changes)

var platformN1 = GetPlatformFromDifferences(symbol, typeName, N1DifferencesRes, N1SDKVersion);

if (!string.IsNullOrEmpty(platformN1.Version))
{
// the entire type was found in Target Version with matching parameter lengths
return new Platform(PlatformKind.Uwp, Analyzer.N0SDKVersion, true);
return platformN1;
}
else
{
TypePresenceIndicator presentInN1ApiDiff = CheckCollectionForType(Analyzer.GetUniversalApiAdditions(Analyzer.N1DifferencesRes), typeName, symbol);

if (presentInN1ApiDiff == TypePresenceIndicator.New)
{
// the entire type was found in Target Version
return new Platform(PlatformKind.Uwp, Analyzer.N1SDKVersion);
}
else if (presentInN1ApiDiff == TypePresenceIndicator.Changes)
{
// the entire type was found in Target Version with matching parameter lengths
return new Platform(PlatformKind.Uwp, Analyzer.N1SDKVersion, true);
}
else
{
// the type was in Min version
return new Platform(PlatformKind.Uwp, Analyzer.N2SDKVersion);
}
var platformN2 = GetPlatformFromDifferences(symbol, typeName, N2DifferencesRes, N2SDKVersion);

if (!string.IsNullOrEmpty(platformN2.Version))
{
return platformN2;
}

return new Platform(PlatformKind.Uwp, Analyzer.BaseSDKVersion);
}

// All other Windows.* types come from platform-specific extensions
Expand All @@ -232,6 +244,27 @@ public static Platform GetPlatformForSymbol(ISymbol symbol)
}
}

private static Platform GetPlatformFromDifferences(ISymbol symbol, string typeName, string differencesRes, string sdkVersion)
{
TypePresenceIndicator presentInApiDiff = CheckCollectionForType(GetUniversalApiAdditions(differencesRes), typeName, symbol);

if (presentInApiDiff == TypePresenceIndicator.New)
{
// the entire type was found in Target Version
return new Platform(PlatformKind.Uwp, sdkVersion);
}
else if (presentInApiDiff == TypePresenceIndicator.Changes)
{
// the entire type was found in Target Version with matching parameter lengths
return new Platform(PlatformKind.Uwp, sdkVersion, true);
}
else
{
// the type was in Min version
return new Platform(PlatformKind.Uwp);
}
}

/// <summary>
/// returns instance of <see cref="HowToGuard"/> for <see cref="ISymbol"/>
/// </summary>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<ItemGroup>
<None Remove="Differences-6.0.0.0.gz" />
<None Remove="Differences-7.0.0.0.gz" />
<None Remove="Differences-8.0.0.0.gz" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Differences-6.0.0.0.gz" />
<EmbeddedResource Include="Differences-7.0.0.0.gz" />
<EmbeddedResource Include="Differences-8.0.0.0.gz" />
</ItemGroup>

<ItemGroup>
Expand Down