Skip to content

Commit 967a6e2

Browse files
authored
Merge pull request #77 from Lorilatschki/dependency_search_fixes
fix: consider types referenced by fields inside ctor base calls
2 parents 577330b + 6815f3b commit 967a6e2

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/NetArchTest.Rules/Dependencies/TypeDefinitionCheckingContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ private void CheckMethodBodyInstructions(MethodDefinition methodToCheck)
220220
}
221221
}
222222
break;
223+
case FieldReference fieldReference:
224+
CheckTypeReference(fieldReference.DeclaringType);
225+
break;
223226
case MethodReference methodReference:
224227
CheckTypeReference( methodReference.DeclaringType);
225228
break;

test/NetArchTest.Rules.UnitTests/DependencySearch/DependencyTypeTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ public void DependencySearch_VariableTupleNested_Found()
396396
public void DependencySearch_VariableTuple_NotFound()
397397
{
398398
Utils.RunDependencyTest(typeof(VariableTuple), typeof(Tuple<int, double>), false, true);
399-
}
399+
}
400+
401+
[Fact(DisplayName = "Finds a dependency StaticType in BaseCtorCall.")]
402+
public void DependencySearch_BaseCtorCall_Found()
403+
{
404+
Utils.RunDependencyTest(typeof(BaseCtorCall), typeof(StaticType), true, true);
405+
}
400406
}
401407
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
3+
namespace NetArchTest.TestStructure.Dependencies.Search.DependencyType
4+
{
5+
public struct Id
6+
{
7+
}
8+
9+
public static class StaticType
10+
{
11+
public static readonly Id SomeId;
12+
}
13+
14+
public abstract class BaseCtorCallBase
15+
{
16+
#pragma warning disable 219
17+
protected BaseCtorCallBase(params Id[] ids)
18+
{
19+
}
20+
#pragma warning restore 219
21+
}
22+
23+
public class BaseCtorCall : BaseCtorCallBase
24+
{
25+
public BaseCtorCall() :
26+
base(StaticType.SomeId)
27+
{
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)