Skip to content

Commit

Permalink
Update dotnet parser to skip RequiresUnreferencedCode attribute (#9680)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkuttappan authored Jan 22, 2025
1 parent 0e78e19 commit 46934b1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
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);
}
}
}

0 comments on commit 46934b1

Please sign in to comment.