Ler em inglês

Compartilhar via


Type.IsPublic Propriedade

Definição

Obtém um valor que indica se o Type está declarado como público.

C#
public bool IsPublic { get; }

Valor da propriedade

Boolean

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

Implementações

Exemplos

O exemplo a seguir cria uma instância de , verifica a MyTestClass propriedade e exibe o IsPublic resultado.

C#
using System;

public class TestClass
{
}

public class Example
{
   public static void Main()
   {
      TestClass testClassInstance = new TestClass();
      // Get the type of myTestClassInstance.
      Type   testType = testClassInstance.GetType();
      // Get the IsPublic property of testClassInstance.
      bool isPublic = testType.IsPublic;
      Console.WriteLine("Is {0} public? {1}", testType.FullName, isPublic);
   }
}
// The example displays the following output:
//        Is TestClass public? True

Para classes aninhadas, ignore os resultados de IsPublic e e preste atenção apenas aos resultados de e IsNotPublic IsNestedPublic IsNestedPrivate .

Comentários

Não use com tipos aninhados; use IsNestedPublic em vez disso.

Se o atual Type representar um parâmetro de tipo de um tipo genérico, essa propriedade retornará true .

TypeAttributes.VisibilityMask seleciona os atributos de visibilidade.

Aplica-se a

Produto Versões
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

Confira também