Export (0) Print
Expand All

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 */
public final boolean get_IsNotPublic ()

public final function get IsNotPublic () : boolean

Not applicable.

Property Value

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

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

import System.*;
import System.IO.*;
import 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}.", 
            System.Convert.ToString(mymemberinfoarray.length),
            myType.get_FullName());
        Console.WriteLine("Is {0} nonpublic? {1}", myType.get_FullName(),
            System.Convert.ToString(myType.get_IsNotPublic()));
    } //main
} //MyMemberInfo

import System;
import System.IO;
import System.Reflection;

class MyMemberInfo { 

  public static function Main() : void  { 

   Console.WriteLine ("\nReflection.MemberInfo");

   //Get the Type and MemberInfo 

   var MyType : Type =Type.GetType("System.IO.File");

   var Mymemberinfoarray : MemberInfo[] = MyType.GetMembers();

   //Get and display the DeclaringType method

   Console.WriteLine("\nThere are {0} members in {1}.",
      Mymemberinfoarray.Length, MyType.FullName);

   Console.WriteLine("Is {0} public? {1}", MyType.FullName,
      MyType.IsPublic.ToString());
  }
}
MyMemberInfo.Main();

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

public class A
{
    public class B
    {
    } //B

    private class C
    {
    } //C
} //A 

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft