Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
zsolt-kolbay-sonarsource committed Jun 13, 2024
1 parent ffd0acc commit 667d9fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public override void VisitAttribute(AttributeSyntax node)
DebuggerDisplayValues.UnionWith(arguments);
}
else if (attribute.Is(KnownType.System_Diagnostics_CodeAnalysis_DynamicallyAccessedMembersAttribute)
&& node.Parent.Parent is BaseTypeDeclarationSyntax typeDeclaration
&& node is { Parent: AttributeListSyntax { Parent: BaseTypeDeclarationSyntax typeDeclaration } }
&& model.GetDeclaredSymbol(typeDeclaration) is { } typeSymbol)
{
TypesUsedWithReflection.Add(typeSymbol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static class Program
public static void Method()
{
var instance = CreateInstance<ClassInstantiatedThroughReflection>();
var instance2 = CreateInstance(typeof(ClassInstantiatedThroughReflection));
var instance2 = CreateInstance(typeof(AnotherClassInstantiatedThroughReflection));

A classViaReflection = new();
InitValue(classViaReflection);
Expand Down Expand Up @@ -212,7 +212,7 @@ private void PrivateMethod() { } // Noncompliant - FP
private ClassInstantiatedThroughReflection() { }
private event EventHandler PrivateEvent; // Noncompliant - FP

public ClassInstantiatedThroughReflection(int arg) // Compliant - the constructor used in CreateInstance through Reflection
public ClassInstantiatedThroughReflection(int arg)
{
}

Expand All @@ -222,6 +222,11 @@ private class NestedType // Noncompliant - FP
}
}

private class AnotherClassInstantiatedThroughReflection
{
private int privateField; // Noncompliant - FP
}

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
private class TypeDecoratedWithDynamicallyAccessedMembers
{
Expand Down

0 comments on commit 667d9fb

Please sign in to comment.