Skip to content

Commit 367d3ba

Browse files
authored
Merge pull request #102 from NeVeSpl/fixFor101
correction of #101 - handle a new compiler generated type <PrivateImplementationDetails>
2 parents 2bb5d38 + 602903b commit 367d3ba

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/NetArchTest.Rules/Dependencies/TypeDefinitionCheckingResult.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using System.Runtime.CompilerServices;
67
using Mono.Cecil;
78
using NetArchTest.Rules.Dependencies.DataStructures;
89

@@ -105,6 +106,10 @@ public void CheckDependency(TypeReference dependency)
105106
if (_hasDependencyFromOutsideOfSearchTree == false)
106107
{
107108
bool isGlobalAnonymousCompilerGeneratedType = String.IsNullOrEmpty(dependency.Namespace) && dependency.Name.StartsWith("<>");
109+
if (dependency is TypeDefinition typeDefinition)
110+
{
111+
isGlobalAnonymousCompilerGeneratedType |= typeDefinition.CustomAttributes.Any(x => x?.AttributeType?.FullName == typeof(CompilerGeneratedAttribute).FullName);
112+
}
108113
if (!isGlobalAnonymousCompilerGeneratedType)
109114
{
110115
_hasDependencyFromOutsideOfSearchTree = true;

src/NetArchTest.Rules/Types.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public sealed class Types
2121

2222
/// <summary> The list of namespaces to exclude from the current domain. </summary>
2323
private static readonly List<string> _exclusionList = new List<string>
24-
{ "System", "Microsoft", "Mono.Cecil", "netstandard", "NetArchTest.Rules", "<Module>", "xunit" };
24+
{ "System", "Microsoft", "Mono.Cecil", "netstandard", "NetArchTest.Rules", "<Module>", "xunit", "<PrivateImplementationDetails>" };
2525

2626
private static readonly NamespaceTree _exclusionTree = new NamespaceTree(_exclusionList);
2727

test/NetArchTest.TestStructure/Dependencies/TypeOfSearch/Classes.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ public static void LetUsCreateSomeAnonymousTypes()
1818
join z in numbers on x equals z
1919
select (x, z);
2020
}
21+
22+
23+
public static int LetUsUseSwitchExpressionWithMoreThan7(string element)
24+
{
25+
return element switch
26+
{
27+
"one" => 1,
28+
"two" => 2,
29+
"three" => 3,
30+
"four" => 4,
31+
"five" => 5,
32+
"six" => 6,
33+
"seven" => 7,
34+
_ => 8,
35+
};
36+
}
2137
}
2238

2339
public class Class_B

0 commit comments

Comments
 (0)