Skip to content

Commit

Permalink
Merge pull request #102 from NeVeSpl/fixFor101
Browse files Browse the repository at this point in the history
correction of #101 - handle a new compiler generated type <PrivateImplementationDetails>
  • Loading branch information
BenMorris authored Jun 26, 2022
2 parents 2bb5d38 + 602903b commit 367d3ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/NetArchTest.Rules/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class Types

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 367d3ba

Please sign in to comment.