Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ private void CheckFields(TypeDefinition typeToCheck)
{
CheckCustomAttributes(field);
CheckTypeReference(field.FieldType);
if (field.HasConstant &&
field.FieldType.FullName == typeof(string).FullName)
{
_result.CheckDependency(field.Constant.ToString());
}
}
}
}
Expand Down Expand Up @@ -140,19 +145,19 @@ private void CheckMethods(TypeDefinition typeToCheck)
foreach (var method in typeToCheck.Methods)
{
if (_result.CanWeSkipFurtherSearch()) return;
this.CheckMethodHeader(method);
CheckMethodHeader(method);
}

foreach (var method in typeToCheck.Methods)
{
if (_result.CanWeSkipFurtherSearch()) return;
this.CheckMethodBodyVariables(method);
CheckMethodBodyVariables(method);
}

foreach (var method in typeToCheck.Methods)
{
if (_result.CanWeSkipFurtherSearch()) return;
this.CheckMethodBodyInstructions(method);
CheckMethodBodyInstructions(method);
}
}
}
Expand Down Expand Up @@ -220,6 +225,9 @@ private void CheckMethodBodyInstructions(MethodDefinition methodToCheck)
}
}
break;
case FieldReference fieldReference:
CheckTypeReference(fieldReference.DeclaringType);
break;
case MethodReference methodReference:
CheckTypeReference( methodReference.DeclaringType);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public bool CanWeSkipFurtherSearch()
}
}

public void CheckDependency(string dependencyTypeFullName)
{
_foundDependencies.Add(dependencyTypeFullName);
}

public void CheckDependency(TypeReference dependency)
{
var matchedDependencies = _searchTree.GetAllMatchingNames(dependency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,18 @@ public void DependencySearch_VariableTupleNested_Found()
public void DependencySearch_VariableTuple_NotFound()
{
Utils.RunDependencyTest(typeof(VariableTuple), typeof(Tuple<int, double>), false, true);
}
}

[Fact(DisplayName = "Finds a dependency StaticType in BaseCtorCall.")]
public void DependencySearch_BaseCtorCall_Found()
{
Utils.RunDependencyTest(typeof(BaseCtorCall), typeof(StaticType), true, true);
}

[Fact(DisplayName = "Finds a dependency when a const string field accesses a type via full type name.")]
public void DependencySearch_ConstFieldString_Found()
{
Utils.RunDependencyTest(typeof(ConstStringFieldValue), typeof(Array), true, true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;

namespace NetArchTest.TestStructure.Dependencies.Search.DependencyType
{
public struct Id
{
}

public static class StaticType
{
public static readonly Id SomeId;
}

public abstract class BaseCtorCallBase
{
#pragma warning disable 219
protected BaseCtorCallBase(params Id[] ids)
{
}
#pragma warning restore 219
}

public class BaseCtorCall : BaseCtorCallBase
{
public BaseCtorCall() :
base(StaticType.SomeId)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NetArchTest.TestStructure.Dependencies.Search.DependencyType
{
public class ConstStringFieldValue
{
#pragma warning disable 219
private const string FullTypeName = "NetArchTest.TestStructure.Dependencies.Search.DependencyType.Array";
#pragma warning restore 219
}
}