Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Type.IsNotPublic Property

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

[Visual Basic]
Public ReadOnly Property IsNotPublic As Boolean
[C#]
public bool IsNotPublic {get;}
[C++]
public: __property bool get_IsNotPublic();
[JScript]
public function get IsNotPublic() : Boolean;

Property Value

true if the top-level Type is not declared public; otherwise, false.

Remarks

IsPublic and IsNotPublic get the visibility of the top-level type only.

VisibilityMask selects the visibility attributes.

Example

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

[Visual Basic] 
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

[C#] 
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());
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
using namespace System::Reflection;

int main() 
{ 
    Console::WriteLine (S"\nReflection.MemberInfo");
    //Get the Type and MemberInfo.
    Type* MyType =Type::GetType(S"System.IO.File");
    MemberInfo* Mymemberinfoarray[] = MyType->GetMembers();
    //Get and display the DeclaringType method.
    Console::WriteLine(S"\nThere are {0} members in {1}.", __box(Mymemberinfoarray->Length), MyType->FullName);
    Console::WriteLine(S"Is {0} nonpublic? {1}",MyType->FullName, __box(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.

[Visual Basic] 
Public Class A
    Public Class B
    End Class
    Private Class C
    End Class
End Class

[C#] 
public class A 
{
    public class B { }
    private class C { }
}

[C++] 
public __gc class A 
{
public:
    __gc class B { };
private:
    __gc class C { };
};

[JScript] 
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

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Type Class | Type Members | System Namespace | TypeAttributes

Show:
© 2014 Microsoft