diff --git a/src/Microsoft.Windows.CsWin32/Generator.cs b/src/Microsoft.Windows.CsWin32/Generator.cs index 80ca2932..62869d65 100644 --- a/src/Microsoft.Windows.CsWin32/Generator.cs +++ b/src/Microsoft.Windows.CsWin32/Generator.cs @@ -436,11 +436,10 @@ public Generator(string metadataLibraryPath, Docs? docs, GeneratorOptions option this.canCallCreateSpan = this.compilation?.GetTypeByMetadataName(typeof(MemoryMarshal).FullName)?.GetMembers("CreateSpan").Any() is true; this.canUseUnsafeAsRef = this.compilation?.GetTypeByMetadataName(typeof(Unsafe).FullName)?.GetMembers("AsRef").Any() is true; this.canUseUnsafeNullRef = this.compilation?.GetTypeByMetadataName(typeof(Unsafe).FullName)?.GetMembers("NullRef").Any() is true; - this.unscopedRefAttributePredefined = this.compilation?.GetTypeByMetadataName("System.Diagnostics.CodeAnalysis.UnscopedRefAttribute") is not null; + this.unscopedRefAttributePredefined = this.FindTypeSymbolIfAlreadyAvailable("System.Diagnostics.CodeAnalysis.UnscopedRefAttribute") is not null; this.getDelegateForFunctionPointerGenericExists = this.compilation?.GetTypeByMetadataName(typeof(Marshal).FullName)?.GetMembers(nameof(Marshal.GetDelegateForFunctionPointer)).Any(m => m is IMethodSymbol { IsGenericMethod: true }) is true; this.generateDefaultDllImportSearchPathsAttribute = this.compilation?.GetTypeByMetadataName(typeof(DefaultDllImportSearchPathsAttribute).FullName) is object; - if (this.compilation?.GetTypeByMetadataName("System.Runtime.Versioning.SupportedOSPlatformAttribute") is { } attribute - && (attribute.DeclaredAccessibility == Accessibility.Public || attribute.ContainingAssembly.GivesAccessTo(this.compilation.Assembly))) + if (this.FindTypeSymbolIfAlreadyAvailable("System.Runtime.Versioning.SupportedOSPlatformAttribute") is { } attribute) { this.generateSupportedOSPlatformAttributes = true; AttributeData usageAttribute = attribute.GetAttributes().Single(att => att.AttributeClass?.Name == nameof(AttributeUsageAttribute)); diff --git a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs index 9bbc1921..56100b61 100644 --- a/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs +++ b/test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs @@ -1511,6 +1511,7 @@ public void ProjectReferenceBetweenTwoGeneratingProjects(bool internalsVisibleTo using var referencedGenerator = this.CreateGenerator(new GeneratorOptions { ClassName = "P1" }, referencedProject); Assert.True(referencedGenerator.TryGenerate("LockWorkStation", CancellationToken.None)); Assert.True(referencedGenerator.TryGenerate("CreateFile", CancellationToken.None)); + Assert.True(referencedGenerator.TryGenerate("RAWHID", CancellationToken.None)); referencedProject = this.AddGeneratedCode(referencedProject, referencedGenerator); this.AssertNoDiagnostics(referencedProject); @@ -1518,6 +1519,7 @@ public void ProjectReferenceBetweenTwoGeneratingProjects(bool internalsVisibleTo this.compilation = this.compilation.AddReferences(referencedProject.ToMetadataReference()); this.generator = this.CreateGenerator(new GeneratorOptions { ClassName = "P2" }); Assert.True(this.generator.TryGenerate("HidD_GetAttributes", CancellationToken.None)); + Assert.True(this.generator.TryGenerate("RAWHID", CancellationToken.None)); this.CollectGeneratedCode(this.generator); this.AssertNoDiagnostics(); }