Skip to content

Commit f37eaf6

Browse files
committed
fix: consider types referenced by non compiler generated fields inside ctor base calls
Moved BaseCtorCall type to example namespace Only consider fields which are not compiler generated
1 parent 94f96ce commit f37eaf6

4 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/NetArchTest.Rules/Dependencies/TypeDefinitionCheckingContext.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ private void CheckMethodBodyInstructions(MethodDefinition methodToCheck)
221221
}
222222
break;
223223
case FieldReference fieldReference:
224-
CheckTypeReference(fieldReference.DeclaringType);
224+
if (!fieldReference.Resolve().CustomAttributes.IsCompilerGenerated())
225+
{
226+
CheckTypeReference(fieldReference.DeclaringType);
227+
}
225228
break;
226229
case MethodReference methodReference:
227230
CheckTypeReference( methodReference.DeclaringType);

src/NetArchTest.Rules/Extensions/TypeDefinitionExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using Mono.Cecil;
77
using System.Runtime.CompilerServices;
8+
using Mono.Collections.Generic;
89

910
/// <summary>
1011
/// Extensions for the <see cref="TypeDefinition"/> class.
@@ -107,7 +108,12 @@ public static bool HasNullableMembers(this TypeDefinition typeDefinition)
107108

108109
public static bool IsCompilerGenerated(this TypeDefinition typeDefinition)
109110
{
110-
return typeDefinition.CustomAttributes.Any(x => x?.AttributeType?.FullName == typeof(CompilerGeneratedAttribute).FullName);
111+
return typeDefinition.CustomAttributes.IsCompilerGenerated();
112+
}
113+
114+
public static bool IsCompilerGenerated(this Collection<CustomAttribute> customAttributes)
115+
{
116+
return customAttributes.Any(x => x?.AttributeType?.FullName == typeof(CompilerGeneratedAttribute).FullName);
111117
}
112118

113119
/// <summary>

src/NetArchTest.Rules/NetArchTest.Rules.xml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/NetArchTest.TestStructure/Dependencies/Search/DependencyType/BaseCtorCall.cs renamed to test/NetArchTest.TestStructure/Dependencies/Examples/BaseCtorCall.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
namespace NetArchTest.TestStructure.Dependencies.Search.DependencyType
1+
namespace NetArchTest.TestStructure.Dependencies.Examples
42
{
53
public struct Id
64
{

0 commit comments

Comments
 (0)