Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResideInNamespaceMatching with nested+internal types #98

Closed
kl1mm opened this issue Sep 22, 2021 · 1 comment
Closed

ResideInNamespaceMatching with nested+internal types #98

kl1mm opened this issue Sep 22, 2021 · 1 comment

Comments

@kl1mm
Copy link

kl1mm commented Sep 22, 2021

Hi BenMorris,
we ran into a problem when trying to validate our nested internal types, which we first filtered for ResideInNamespaceMatching.

After examining the NetArchTest code, we found the extension method TypeDefinitionExtensions.GetNamespace, which only checks IsNestedPrivate or IsNestedPublic. For testing, we changed our class from internal to private and it worked.

        public static string GetNamespace(this TypeDefinition typeDefinition)
        {
            if (typeDefinition.IsNestedPrivate || typeDefinition.IsNestedPublic)
            {
                return typeDefinition.DeclaringType.FullName;
            }

            return typeDefinition.Namespace;
        }
NeVeSpl added a commit to NeVeSpl/NetArchTest that referenced this issue Oct 10, 2021
@NeVeSpl
Copy link
Contributor

NeVeSpl commented Oct 10, 2021

I do not know what the author had in mind by restricting it only to private and public nested types, especially that in another place it is less restrictive:

public static string GetNamespace(this TypeReference typeReference)
{
if (typeReference.IsNested)
{
return typeReference?.DeclaringType.FullName;
}
return typeReference.Namespace;
}

I guess it is my mistake, since I am the one who wrote both methods :D .

BenMorris added a commit that referenced this issue Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants