英語で読む

次の方法で共有


Type.IsContextful プロパティ

定義

Type をコンテキスト内で管理できるかどうかを示す値を取得します。

C#
public bool IsContextful { get; }

プロパティ値

Boolean

true をコンテキスト内でホストできる場合は Type。それ以外の場合は false

実装

次の例は、 クラスの IsContextful IsMarshalByRef 、、 IsPrimitive および のプロパティを示 Type しています。 指定した型をコンテキストでホストできるかどうか、参照によってマーシャリングできるかどうか、および型がプリミティブ データ型であるかどうかを確認します。

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.

注釈

コンテキストは、クラス メンバーの呼び出しをインターセプトし、同期などのクラスに適用されるポリシーを適用します。 リモート処理コンテキストの詳細については、「」を参照してください Context

現在の がジェネリック型またはジェネリック メソッドの定義で型パラメーターを表している場合、このプロパティは常に Type を返します false

適用対象

製品 バージョン
.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

こちらもご覧ください