Gets a value indicating whether the Type is not declared public.
Assembly: mscorlib (in mscorlib.dll)
Public ReadOnly Property IsNotPublic As Booleanpublic bool IsNotPublic { get; }public:
virtual property bool IsNotPublic {
bool get () sealed;
}abstract IsNotPublic : bool
override IsNotPublic : boolProperty Value
Type: Systemtrue if the Type is not declared public and is not a nested type; otherwise, false.
Implements
_TypeDo 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
This example shows the use of IsNotPublic to get the visibility of the type.
Imports System
Imports System.IO
Imports System.Reflection
Imports Microsoft.VisualBasic
Class MyMemberInfo
Public Shared Sub Main()
Console.WriteLine(ControlChars.Cr + "Reflection.MemberInfo")
'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.
Console.WriteLine(ControlChars.Cr + "There are {0} members in {1}.", _
Mymemberinfoarray.Length, MyType.FullName)
Console.WriteLine("Is {0} nonpublic? {1}", MyType.FullName, _
MyType.IsNotPublic.ToString())
End Sub
End Class
using System;
using System.IO;
using System.Reflection;
class MyMemberInfo
{
public static void Main(string[] args)
{
Console.WriteLine ("\nReflection.MemberInfo");
//Get the Type and MemberInfo.
Type MyType =Type.GetType("System.IO.File");
MemberInfo[] Mymemberinfoarray = MyType.GetMembers();
//Get and display the DeclaringType method.
Console.WriteLine("\nThere are {0} members in {1}.", Mymemberinfoarray.Length, MyType.FullName);
Console.WriteLine("Is {0} nonpublic? {1}", MyType.FullName, MyType.IsNotPublic.ToString());
}
}
using namespace System;
using namespace System::IO;
using namespace System::Reflection;
int main()
{
Console::WriteLine( "\nReflection.MemberInfo" );
//Get the Type and MemberInfo.
Type^ MyType = Type::GetType( "System.IO.File" );
array<MemberInfo^>^Mymemberinfoarray = MyType->GetMembers();
//Get and display the DeclaringType method.
Console::WriteLine( "\nThere are {0} members in {1}.", Mymemberinfoarray->Length, MyType->FullName );
Console::WriteLine( "Is {0} nonpublic? {1}", MyType->FullName, MyType->IsNotPublic );
}
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 { }
}
public ref class A
{
public:
ref class B{};
private:
ref 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 |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.