Why is the inner class not publicly available when viewed in reflection?

AKA, why does this test fail?

[TestFixture]
public class Tests
{
    [Test]
    public void InnerClassShouldBePublic()
    {
        Assert.IsTrue(typeof (InnerClass).IsPublic);
    }

    public class InnerClass
    {
    }

}
+5
source share
1 answer

It fails because nested types are not considered Public , they are considered NestedPublic.

From the IsPublic()MSDN Documentation :

Do not use with nested types; use instead IsNestedPublic.

+8
source

All Articles