Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are inner class not public 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
    {
    }

}
like image 347
Simon Avatar asked Feb 17 '13 04:02

Simon


1 Answers

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

From the IsPublic() MSDN documentation:

Do not use with nested types; use IsNestedPublic instead.

like image 96
shf301 Avatar answered Sep 27 '22 19:09

shf301