Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Type.IsPublic and Type.IsVisible

Tags:

c#

reflection

clr

In C# the Type class instances have a lot of properties. Two of them are IsPublic and IsVisible:

  • Type.IsPublic - Gets a value indicating whether the Type is declared public.
  • Type.IsVisible - Gets a value indicating whether the Type can be accessed by code outside the assembly.

As far as I know all public members can be accessed outside of the assembly and all others cannot. Two exceptions I can think of are the [InternalsVisibleTo:] assembly attribute and protected modifier for members.

But anyway what is the difference between these two properties?

like image 767
Nikolay Kostov Avatar asked Dec 22 '25 13:12

Nikolay Kostov


1 Answers

The links you posted explain this:

IsPublic returns

true if the Type is declared public and is not a nested type; otherwise, false.

IsVisible returns

true if the current Type is a public type or a public nested type such that all the enclosing types are public; otherwise, false.

like image 85
Matteo Umili Avatar answered Dec 24 '25 04:12

Matteo Umili



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!