IsNotPublic Property

Type.IsNotPublic Property

 

Gets a value indicating whether the Type is not declared public.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

Public ReadOnly Property IsNotPublic As Boolean

Property Value

Type: System.Boolean

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

Do not use this property with nested types; use the IsNestedPublicproperty instead.

If the current Type represents a type parameter of a generic type, this property returns false.

This example usesthe IsNotPublicproperty to get the visibility of the type.

Imports System.IO
Imports System.Reflection

Module Example
    Public Sub Main()
        'Get the Type and MemberInfo.
        Dim t As Type = Type.GetType("System.IO.File")
        Dim members As MemberInfo() = t.GetMembers()
        'Get and display the DeclaringType method.
        Console.WriteLine("There are {0} members in {1}.",
                          members.Length, t.FullName)
        Console.WriteLine("Is {0} non-public? {1}",
                          t.FullName, t.IsNotPublic)
    End Sub
End Module
' The example displays output like the following:
'       There are 60 members in System.IO.File.
'       Is System.IO.File non-public? False

The following code example demonstrates why you cannot use IsPublic and IsNotPublic for nested classes.

Public Class A
    Public Class B
    End Class
    Private Class C
    End Class
End Class

For nested classes, ignore the results of IsPublic and IsNotPublic and pay attention only to the results of IsNestedPublic and IsNestedPrivate. The reflection output for this code fragment would be as follows:

Class

IsNotPublic

IsPublic

IsNestedPublic

IsNestedPrivate

A

FALSE

TRUE

FALSE

FALSE

B

FALSE

FALSE

TRUE

FALSE

C

FALSE

FALSE

FALSE

TRUE

.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show:
© 2016 Microsoft