Type.IsContextful プロパティ
Type をコンテキスト内で管理できるかどうかを示す値を取得します。
Public ReadOnly Property IsContextful As Boolean
[C#]
public bool IsContextful {get;}
[C++]
public: __property bool get_IsContextful();
[JScript]
public function get IsContextful() : Boolean;
プロパティ値
Type をコンテキスト内で管理できる場合は true 。それ以外の場合は false 。
解説
コンテキストは、クラス メンバに対する呼び出しを認識し、そのクラスに適用される同期などのポリシーを強制的に適用します。リモート処理コンテキストの詳細については、「 Context 」を参照してください。
使用例
[Visual Basic, C#, C++] Type クラスの IsContextful 、 IsMarshalByRef 、 IsPrimitive の各プロパティの例を次に示します。これは、指定された型がこのコンテキストにホストできるかどうか、参照によってマーシャリングできるかどうか、指定された型がプリミティブ データ型かどうかを確認します。
Imports System
Imports System.Runtime.Remoting.Contexts
Imports Microsoft.VisualBasic
Public Class MyContextBoundClass
Inherits ContextBoundObject
Public myString As String = "This class demonstrates the IsContextful, IsMarshalByRef, and IsPrimitive properties."
End Class 'MyContextBoundClass
Public Class MyTypeDemoClass
Public Shared Sub Main()
Try
' Determine whether the types can be hosted in a Context.
Console.WriteLine("The Contextful property for the {0} type is {1}.", GetType(MyTypeDemoClass).Name, GetType(MyTypeDemoClass).IsContextful.ToString())
Console.WriteLine("The Contextful property for the {0} type is {1}.", GetType(MyContextBoundClass).Name, GetType(MyContextBoundClass).IsContextful.ToString())
' Determine whether the types are marshalled by reference.
Console.WriteLine("The MarshalByRef property of {0} is {1}.", GetType(MyTypeDemoClass).Name, GetType(MyTypeDemoClass).IsMarshalByRef.ToString())
Console.WriteLine("The MarshalByRef property of {0} is {1}.", GetType(MyContextBoundClass).Name, GetType(MyContextBoundClass).IsMarshalByRef.ToString())
' Determine whether the types are primitive datatypes.
Console.WriteLine("Is {0} a primitive data type? {1}.", GetType(Integer).Name, GetType(Integer).IsPrimitive.ToString())
Console.WriteLine("Is {0} a primitive data type? {1}.", GetType(String).Name, GetType(String).IsPrimitive.ToString())
Catch e As Exception
Console.WriteLine("An exception occurred: " + e.Message.ToString())
End Try
End Sub 'Main
End Class 'MyTypeDemoClass
[C#]
using System;
using System.Runtime.Remoting.Contexts;
public class MyContextBoundClass: ContextBoundObject
{
public string myString = "This class demonstrates the IsContextful, IsMarshalByRef, and IsPrimitive properties.";
}
public class MyTypeDemoClass
{
public static void Main()
{
try
{
// Determine whether the types can be hosted in a Context.
Console.WriteLine ("The IsContextful property for the {0} type is {1}.", typeof(MyTypeDemoClass).Name, typeof(MyTypeDemoClass).IsContextful);
Console.WriteLine ("The IsContextful property for the {0} type is {1}.", typeof(MyContextBoundClass).Name, typeof(MyContextBoundClass).IsContextful);
// Determine whether the types are marshalled by reference.
Console.WriteLine ("The MarshalByRef property of {0} is {1}.", typeof(MyTypeDemoClass).Name, typeof(MyTypeDemoClass).IsMarshalByRef);
Console.WriteLine ("The MarshalByRef property of {0} is {1}.", typeof(MyContextBoundClass).Name, typeof(MyContextBoundClass).IsMarshalByRef);
// Determine whether the types are primitive datatypes.
Console.WriteLine ("Is {0} is a primitive data type? {1}.", typeof(int).Name, typeof(int).IsPrimitive);
Console.WriteLine ("Is {0} a primitive data type? {1}.", typeof(string).Name, typeof(string).IsPrimitive);
}
catch (Exception e)
{
Console.WriteLine("An exception occurred: " + e.Message);
}
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::Remoting::Contexts;
public __gc class MyContextBoundClass : public ContextBoundObject {
public:
String* myString;
};
public __gc class MyTypeDemoClass {
public:
void Demo() {
try {
// Determine whether the types can be hosted in a Context.
Console::WriteLine (S"The IsContextful property for the {0} type is {1}.", __typeof(MyTypeDemoClass)->Name,__box( __typeof(MyTypeDemoClass)->IsContextful));
Console::WriteLine (S"The IsContextful property for the {0} type is {1}.", __typeof(MyContextBoundClass)->Name, __box(__typeof(MyContextBoundClass)->IsContextful));
// Determine whether the types are marshalled by reference.
Console::WriteLine (S"The MarshalByRef property of {0} is {1}.", __typeof(MyTypeDemoClass)->Name,__box( __typeof(MyTypeDemoClass)->IsMarshalByRef));
Console::WriteLine (S"The MarshalByRef property of {0} is {1}.", __typeof(MyContextBoundClass)->Name,__box( __typeof(MyContextBoundClass)->IsMarshalByRef));
// Determine whether the types are primitive datatypes.
Console::WriteLine (S"Is {0} is a primitive data type? {1}.", __typeof(int)->Name,__box( __typeof(int)->IsPrimitive));
Console::WriteLine (S"Is {0} a primitive data type? {1}.", __typeof(String)->Name, __box(__typeof(String)->IsPrimitive));
} catch (Exception* e) {
Console::WriteLine(S"An exception occurred: {0}", e->Message);
}
}
};
int main()
{
MyTypeDemoClass* mtdc = new MyTypeDemoClass();
mtdc->Demo();
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ