Type.IsNotPublic Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public ReadOnly Property IsNotPublic As Boolean
public bool IsNotPublic { get; }

Property Value

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

Remarks

Do not use with nested types; use IsNestedPublic instead.

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

TypeAttributes.VisibilityMask selects the visibility attributes.

Examples

This example shows the use of IsNotPublic to get the visibility of the type.

Imports System.IO
Imports System.Reflection
Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      outputBlock.Text &= ControlChars.Cr + "Reflection.MemberInfo" & vbCrLf
      'Get the Type and MemberInfo.
      Dim MyType As Type = Type.GetType("System.IO.File")
      Dim Mymemberinfoarray As MemberInfo() = MyType.GetMembers()
      'Get and display the DeclaringType method.
      outputBlock.Text &= String.Format(ControlChars.Cr + "There are {0} members in {1}.", _
         Mymemberinfoarray.Length, MyType.FullName) & vbCrLf
      outputBlock.Text &= String.Format("Is {0} nonpublic? {1}", MyType.FullName, _
         MyType.IsNotPublic.ToString()) & vbCrLf
   End Sub
End Class
using System;
using System.IO;
using System.Reflection;
class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "\nReflection.MemberInfo" + "\n";
      //Get the Type and MemberInfo.
      Type MyType = Type.GetType("System.IO.File");
      MemberInfo[] Mymemberinfoarray = MyType.GetMembers();
      //Get and display the DeclaringType method.
      outputBlock.Text += String.Format("\nThere are {0} members in {1}.", Mymemberinfoarray.Length, MyType.FullName) + "\n";
      outputBlock.Text += String.Format("Is {0} nonpublic? {1}", MyType.FullName, MyType.IsNotPublic.ToString()) + "\n";
   }
}

This code produces the following output:

There are 27 members in System.IO.File.
Is System.IO.File 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
public class A
{
   public class B { }
   private class C { }
}

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

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.