Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dotnet parser to skip RequiresUnreferencedCode attribute #9680

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 @@ -9,6 +9,7 @@
using System.Collections.Immutable;
using System.ComponentModel;
using ApiView;
using System.Diagnostics.CodeAnalysis;

namespace CSharpAPIParser.TreeToken
{
Expand Down Expand Up @@ -540,6 +541,8 @@ private bool IsSkippedAttribute(INamedTypeSymbol attributeAttributeClass)
case "EditorBrowsableAttribute":
case "NullableAttribute":
case "NullableContextAttribute":
case "RequiresUnreferencedCodeAttribute":
case "RequiresDynamicCodeAttribute":
return true;
default:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.42.0" />
<PackageReference Include="Azure.Core" Version="1.44.1" />
<PackageReference Include="Azure.Core.Expressions.DataFactory" Version="1.0.0" />
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.3" />
<PackageReference Include="Azure.Security.Attestation" Version="1.0.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.21.2" />
<PackageReference Include="Azure.Template" Version="1.0.3-beta.4055065" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static CodeFileTests()
{
new object[] { templateCodeFile, "Azure.Template" , "1.0.3.0", 9},
new object[] { storageCodeFile , "Azure.Storage.Blobs", "12.21.2.0", 15},
new object[] { coreCodeFile, "Azure.Core", "1.42.0.0", 27},
new object[] { coreCodeFile, "Azure.Core", "1.44.1.0", 27},
};

[Theory]
Expand Down Expand Up @@ -365,5 +365,26 @@ public void VerifyTemplateClassLine()
Assert.NotNull(methodLine);
Assert.Equal("public static DataFactoryElement<string?> FromKeyVaultSecret(DataFactoryKeyVaultSecret secret);", methodLine.ToString().Trim());
}

[Fact]
public void VerifySkippedAttributes()
{
var serviceBusAssembly = Assembly.Load("Azure.Messaging.ServiceBus");
var dllStream = serviceBusAssembly.GetFile("Azure.Messaging.ServiceBus.dll");
var assemblySymbol = CompilationFactory.GetCompilation(dllStream, null);
var codeFile = new CSharpAPIParser.TreeToken.CodeFileBuilder().Build(assemblySymbol, true, null);

var line = codeFile.ReviewLines.Where(l => l.LineId == "Microsoft.Extensions.Azure").FirstOrDefault();
Assert.NotNull(line);
var classLine = line.Children?.Where(l => l.LineId == "Microsoft.Extensions.Azure.ServiceBusClientBuilderExtensions").FirstOrDefault();
Assert.NotNull(classLine);
var methodLine = classLine.Children?.Where(l => l.LineId.Contains("Microsoft.Extensions.Azure.ServiceBusClientBuilderExtensions.AddServiceBusClient")).FirstOrDefault();
Assert.NotNull(methodLine);

bool isRequiresUnreferencedCodePresent = classLine.Children?.Any(l => l.Tokens.Any(t => t.Value == "RequiresUnreferencedCodeAttribute")) ?? false;
bool isRequiresDynamicCode = classLine.Children?.Any(l => l.Tokens.Any(t => t.Value == "RequiresDynamicCode")) ?? false;
Assert.False(isRequiresUnreferencedCodePresent);
Assert.False(isRequiresDynamicCode);
}
}
}
Loading