Skip to content

Support constants #383

@petermorlion

Description

@petermorlion

Is it possible to support constants when checking if a type references other types?

Consider this test:

var architecture = new ArchLoader().LoadAssemblies(
    typeof(Class1).Assembly,
    typeof(Names).Assembly
    ).Build();

var coreClasses = Types().That().ResideInAssembly(typeof(Class1).Assembly);
var nameClasses = Types().That().ResideInAssembly(typeof(Names).Assembly);

var rule = coreClasses 
    .Should()
    .NotDependOnAny(nameClasses );

rule.Check(architecture);

Given this code:

namespace ArchUnitSample
{
    public class Class1
    {
        public string Name = Names.JohnDoe;
    }
}

...

namespace ArchUnitSample2
{
    public static class Names
    {
        // With this code snippet, the architecture rule fails
        //public static string JohnDoe = "John Doe";

        // With this code snippet, the architecture rule doesn't fail
        public const string JohnDoe = "John Doe";
    }
}

The test fails when we use the static property but doesn't when we use the const. I'm aware of the underlying difference between constants and statics, so that may be the cause. But I feel this rule then lets a violation slip through. In my case, this could be fixed with #130 but still, I wonder if this can be fixed.

Metadata

Metadata

Assignees

Labels

triage/wont-fixIndicates an issue that can not or will not be resolved.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions