Ler em inglês

Compartilhar via


Type.IsContextful Propriedade

Definição

Obtém um valor que indica se o Type pode ser hospedado em um contexto.

C#
public bool IsContextful { get; }

Valor da propriedade

Boolean

true se o Type puder ser hospedado em um contexto; caso contrário, false.

Implementações

Exemplos

O exemplo a seguir demonstra IsContextful as IsMarshalByRef Propriedades, e IsPrimitive da Type classe. Ele verifica se o tipo fornecido pode ser hospedado no contexto, se ele pode ser empacotado por referência e se o tipo é um tipo de dados primitivo.

C#
using System;
using System.Runtime.Remoting.Contexts;

public class ContextBoundClass: ContextBoundObject
{
    public string Value = "The Value property.";
}

public class Example
{
    public static void Main()
    {
         // Determine whether the types can be hosted in a Context.
         Console.WriteLine("The IsContextful property for the {0} type is {1}.",
                           typeof(Example).Name, typeof(Example).IsContextful);
         Console.WriteLine("The IsContextful property for the {0} type is {1}.",
                           typeof(ContextBoundClass).Name, typeof(ContextBoundClass).IsContextful);

         // Determine whether the types are marshalled by reference.
         Console.WriteLine("The IsMarshalByRef property of {0} is {1}.",
                           typeof(Example).Name, typeof(Example).IsMarshalByRef);
         Console.WriteLine("The IsMarshalByRef property of {0} is {1}.",
                           typeof(ContextBoundClass).Name, typeof(ContextBoundClass).IsMarshalByRef);

         // Determine whether the types are primitive datatypes.
         Console.WriteLine("{0} is a primitive data type: {1}.",
                           typeof(int).Name, typeof(int).IsPrimitive);
         Console.WriteLine("{0} is a primitive data type: {1}.",
                           typeof(string).Name, typeof(string).IsPrimitive);
    }
}
// The example displays the following output:
//    The IsContextful property for the Example type is False.
//    The IsContextful property for the ContextBoundClass type is True.
//    The IsMarshalByRef property of Example is False.
//    The IsMarshalByRef property of ContextBoundClass is True.
//    Int32 is a primitive data type: True.
//    String is a primitive data type: False.

Comentários

Um contexto intercepta chamadas para os membros da classe e impõe políticas que são aplicadas à classe, como sincronização. Para obter informações mais detalhadas sobre contextos de comunicação remota, consulte Context .

Caso o Type atual represente um parâmetro de tipo na definição de um tipo genérico ou um método genérico, esta propriedade sempre retorna false.

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