Skip to content
Merged
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 @@ -32,5 +32,10 @@ public IEnumerable<string> GetAllMatchingNames(TypeReference type)
}
return node.value;
}

public IEnumerable<string> GetAllMatchingNames(string fullName)
{
return _searchTree.GetAllMatchingNames(fullName).ToArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
internal interface ISearchTree
{
IEnumerable<string> GetAllMatchingNames(TypeReference type);
IEnumerable<string> GetAllMatchingNames(string fullName);
int TerminatedNodesCount { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ 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 +144,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
16 changes: 16 additions & 0 deletions src/NetArchTest.Rules/Dependencies/TypeDefinitionCheckingResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ public bool CanWeSkipFurtherSearch()
}
}

public void CheckDependency(string dependencyTypeFullName)
{
var matchedDependencies = _searchTree.GetAllMatchingNames(dependencyTypeFullName);
if (matchedDependencies.Any())
{
foreach (var match in matchedDependencies)
{
_foundDependencies.Add(match);
}
}
else
{
_hasDependencyFromOutsideOfSearchTree = true;
}
}

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

[Fact(DisplayName = "Finds a dependency Array in ConstStringFieldValue.")]
public void DependencySearch_ConstFieldString_Found()
{
Utils.RunDependencyTest(typeof(ConstStringFieldValue), typeof(Array), true, true);
}

[Fact(DisplayName = "Does not find a dependency ArrayJagged in ConstStringFieldValue.")]
public void DependencySearch_ConstFieldString_NotFound()
{
Utils.RunDependencyTest(typeof(ConstStringFieldValue), typeof(ArrayJagged), false, true);
}

[Fact(DisplayName = "Finds a dependency StaticType in BaseCtorCall.")]
public void DependencySearch_BaseCtorCall_Found()
{
Expand Down
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
}
}