Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Type.IsNotPublic Property

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
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.

Implements

_Type.IsNotPublic

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.

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

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());
    }
}

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 { }
    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

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.