Compartilhar via


Type.IsNotPublic Propriedade

Definição

Obtém um valor que indica se o Type não é declarado público.

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

Valor da propriedade

true se o Type não for declarado público e não for um tipo aninhado; caso contrário, false.

Implementações

Exemplos

Este exemplo usa a IsNotPublic propriedade para obter a visibilidade do tipo.

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
open System

// Get the Type and MemberInfo.
let t = Type.GetType "System.IO.File"
let members = t.GetMembers()
// Get and display the DeclaringType method.
printfn $"\nThere are {members.Length} members in {t.FullName}."
printfn $"Is {t.FullName} non-public? {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

O exemplo de código a seguir demonstra por que você não pode usar IsPublic e IsNotPublic para classes aninhadas.

public class A
{
    public class B { }
    private class C { }
}
module A =
    type B() = class end
    type C() = class end
Public Class A
    Public Class B
    End Class
    Private Class C
    End Class
End Class

Para classes aninhadas, ignore os resultados e IsNotPublicIsPublic preste atenção apenas aos resultados de IsNestedPublic e IsNestedPrivate. A saída de reflexão para este fragmento de código seria a seguinte:

Classe Isnotpublic IsPublic Isnestedpublic Isnestedprivate
Um FALSE VERDADEIRO FALSE FALSE
B FALSE FALSE VERDADEIRO FALSE
C FALSE FALSE FALSE VERDADEIRO

Comentários

Não use essa propriedade com tipos aninhados; em vez disso, use a IsNestedPublic propriedade.

Se a corrente Type representar um parâmetro de tipo de um tipo genérico, essa propriedade retornará false.

Aplica-se a

Confira também