diff --git a/src/NetArchTest.Rules/Dependencies/TypeDefinitionCheckingResult.cs b/src/NetArchTest.Rules/Dependencies/TypeDefinitionCheckingResult.cs
index 1143e39..37b9881 100644
--- a/src/NetArchTest.Rules/Dependencies/TypeDefinitionCheckingResult.cs
+++ b/src/NetArchTest.Rules/Dependencies/TypeDefinitionCheckingResult.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+ using System.Runtime.CompilerServices;
using Mono.Cecil;
using NetArchTest.Rules.Dependencies.DataStructures;
@@ -105,6 +106,10 @@ public void CheckDependency(TypeReference dependency)
if (_hasDependencyFromOutsideOfSearchTree == false)
{
bool isGlobalAnonymousCompilerGeneratedType = String.IsNullOrEmpty(dependency.Namespace) && dependency.Name.StartsWith("<>");
+ if (dependency is TypeDefinition typeDefinition)
+ {
+ isGlobalAnonymousCompilerGeneratedType |= typeDefinition.CustomAttributes.Any(x => x?.AttributeType?.FullName == typeof(CompilerGeneratedAttribute).FullName);
+ }
if (!isGlobalAnonymousCompilerGeneratedType)
{
_hasDependencyFromOutsideOfSearchTree = true;
diff --git a/src/NetArchTest.Rules/Types.cs b/src/NetArchTest.Rules/Types.cs
index 9647026..6841e9d 100644
--- a/src/NetArchTest.Rules/Types.cs
+++ b/src/NetArchTest.Rules/Types.cs
@@ -21,7 +21,7 @@ public sealed class Types
/// The list of namespaces to exclude from the current domain.
private static readonly List _exclusionList = new List
- { "System", "Microsoft", "Mono.Cecil", "netstandard", "NetArchTest.Rules", "", "xunit" };
+ { "System", "Microsoft", "Mono.Cecil", "netstandard", "NetArchTest.Rules", "", "xunit", "" };
private static readonly NamespaceTree _exclusionTree = new NamespaceTree(_exclusionList);
diff --git a/test/NetArchTest.TestStructure/Dependencies/TypeOfSearch/Classes.cs b/test/NetArchTest.TestStructure/Dependencies/TypeOfSearch/Classes.cs
index ed5f1ae..cd80bd1 100644
--- a/test/NetArchTest.TestStructure/Dependencies/TypeOfSearch/Classes.cs
+++ b/test/NetArchTest.TestStructure/Dependencies/TypeOfSearch/Classes.cs
@@ -18,6 +18,22 @@ public static void LetUsCreateSomeAnonymousTypes()
join z in numbers on x equals z
select (x, z);
}
+
+
+ public static int LetUsUseSwitchExpressionWithMoreThan7(string element)
+ {
+ return element switch
+ {
+ "one" => 1,
+ "two" => 2,
+ "three" => 3,
+ "four" => 4,
+ "five" => 5,
+ "six" => 6,
+ "seven" => 7,
+ _ => 8,
+ };
+ }
}
public class Class_B