Type.IsNotPublic Propiedad

Definición

Obtiene un valor que indica si el objeto Type no se ha declarado público.

public:
 property bool IsNotPublic { bool get(); };
public bool IsNotPublic { get; }
member this.IsNotPublic : bool
Public ReadOnly Property IsNotPublic As Boolean

Valor de propiedad

Boolean

true si el objeto Type no se ha declarado público y no es un tipo anidado; de lo contrario, false.

Implementaciones

Ejemplos

En este ejemplo se IsNotPublic usa la propiedad para obtener la visibilidad del tipo.

using namespace System;
using namespace System::IO;
using namespace System::Reflection;

int main()
{
   //Get the Type and MemberInfo.
   Type^ t = Type::GetType("System.IO.File");
   array<MemberInfo^>^ members = t->GetMembers();
   
   //Get and display the DeclaringType method.
   Console::WriteLine("There are {0} members in {1}.",
                      members->Length, t->FullName );
   Console::WriteLine("Is {0} non-public? {1}",
                      t->FullName, t->IsNotPublic );
}
// The example displays the following output:
//       There are 60 members in System.IO.File.
//       Is System.IO.File non-public? False
using System;
using System.IO;
using System.Reflection;

class Example
{
    public static void Main()
    {
        // Get the Type and MemberInfo.
        Type t = Type.GetType("System.IO.File");
        MemberInfo[] members = t.GetMembers();
        // Get and display the DeclaringType method.
        Console.WriteLine("\nThere are {0} members in {1}.",
                          members.Length, t.FullName);
        Console.WriteLine("Is {0} non-public? {1}",
                          t.FullName, t.IsNotPublic);
    }
}
// The example displays output like the following:
//       There are 60 members in System.IO.File.
//       Is System.IO.File non-public? False
Imports System.IO
Imports System.Reflection

Module Example
    Public Sub Main()
        'Get the Type and MemberInfo.
        Dim t As Type = Type.GetType("System.IO.File")
        Dim members As MemberInfo() = t.GetMembers()
        'Get and display the DeclaringType method.
        Console.WriteLine("There are {0} members in {1}.",
                          members.Length, t.FullName)
        Console.WriteLine("Is {0} non-public? {1}",
                          t.FullName, t.IsNotPublic)
    End Sub
End Module
' The example displays output like the following:
'       There are 60 members in System.IO.File.
'       Is System.IO.File non-public? False

En el ejemplo de código siguiente se muestra por qué no se puede usar IsPublic y para las clases IsNotPublic anidadas.

public ref class A
{
public:
   ref class B{};


private:
   ref class C{};


};
public class A
{
    public class B { }
    private class C { }
}
Public Class A
    Public Class B
    End Class
    Private Class C
    End Class
End Class

En el caso de las clases anidadas, ignore los resultados de y y y preste atención solo a IsPublic IsNotPublic los resultados de y IsNestedPublic IsNestedPrivate . La salida de reflexión para este fragmento de código sería la siguiente:

Clase IsNotPublic IsPublic IsNestedPublic IsNestedPrivate
A false true false false
B false false true false
C false false false true

Comentarios

No use esta propiedad con tipos anidados; use la IsNestedPublic propiedad en su lugar.

Si el objeto Type actual representa un parámetro de tipo de un tipo genérico, esta propiedad devuelve false .

Se aplica a

Consulte también