次の方法で共有


Type.IsContextfulImpl メソッド

IsContextful プロパティを実装し、 Type をコンテキスト内で管理できるかどうかを判断します。

Protected Overridable Function IsContextfulImpl() As Boolean
[C#]
protected virtual bool IsContextfulImpl();
[C++]
protected: virtual bool IsContextfulImpl();
[JScript]
protected function IsContextfulImpl() : Boolean;

戻り値

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

解説

このメソッドは、派生クラスでオーバーライドできます。

コンテキストは、クラス メンバに対する呼び出しを受け取り、クラスに適用される同期などのポリシーを強制的に実行します。

使用例

[Visual Basic, C#, C++] IsContextfulImpl メソッドを使用する例を次に示します。

 
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class MyTypeDelegatorClass
    Inherits TypeDelegator
    Public myElementType As String = Nothing
    Private myType As Type = Nothing
    Public Sub New(ByVal myType As Type)
        MyBase.New(myType)
        Me.myType = myType
    End Sub 'New
    ' Override IsContextfulImpl.
    Protected Overrides Function IsContextfulImpl() As Boolean
        ' Check whether the type is contextful.
        If myType.IsContextful Then
            myElementType = " is contextful "
            Return True
        End If
        Return False
    End Function 'IsContextfulImpl
End Class 'MyTypeDelegatorClass
Public Class MyTypeDemoClass
    Public Shared Sub Main()
        Try
            Dim myType As MyTypeDelegatorClass
            Console.WriteLine("Check whether MyContextBoundClass can be hosted in a context.")
            ' Check whether MyContextBoundClass is contextful.
            myType = New MyTypeDelegatorClass(GetType(MyContextBoundClass))
            If myType.IsContextful Then
                Console.WriteLine(GetType(MyContextBoundClass).ToString() + " can be hosted in a context.")
            Else
                Console.WriteLine(GetType(MyContextBoundClass).ToString() + " cannot be hosted in a context.")
            End If
            ' Check whether the int type is contextful.
            myType = New MyTypeDelegatorClass(GetType(MyTypeDemoClass))
            Console.WriteLine(ControlChars.NewLine + "Check whether MyTypeDemoClass can be hosted in a context.")
            If myType.IsContextful Then
                Console.WriteLine(GetType(MyTypeDemoClass).ToString() + " can be hosted in a context.")
            Else
                Console.WriteLine(GetType(MyTypeDemoClass).ToString() + " cannot be hosted in a context.")
            End If
        Catch e As Exception
            Console.WriteLine("Exception: {0}", e.Message.ToString())
        End Try
    End Sub 'Main
End Class 'MyTypeDemoClass
' This class demonstrates the IsContextfulImpl method.
Public Class MyContextBoundClass
    Inherits ContextBoundObject
    Public myString As String = "This class is used to demonstrate members of the Type class."
End Class 'MyContextBoundClass

[C#] 
using System;
using System.Reflection;
public class MyTypeDelegatorClass : TypeDelegator
{
    public string myElementType = null;
    private Type myType = null ; 

    public MyTypeDelegatorClass(Type myType) : base(myType)
    {
        this.myType = myType;
    }
    // Override IsContextfulImpl.
    protected override bool IsContextfulImpl()
    {
        // Check whether the type is contextful.
        if(myType.IsContextful)
        { 
            myElementType = " is contextful ";
            return true;
        }
        return false;
    }
}
public class MyTypeDemoClass
{
    public static void Main()
    {
        try
        {
            MyTypeDelegatorClass myType;
            Console.WriteLine ("Check whether MyContextBoundClass can be hosted in a context.");
            // Check whether MyContextBoundClass is contextful.
            myType = new MyTypeDelegatorClass(typeof(MyContextBoundClass));
            if( myType.IsContextful)
            {
                Console.WriteLine(typeof(MyContextBoundClass) + " can be hosted in a context.");
            }
            else
            {
                Console.WriteLine(typeof(MyContextBoundClass) + " cannot be hosted in a context.");
            }
            // Check whether the int type is contextful.
            myType = new MyTypeDelegatorClass(typeof(MyTypeDemoClass));
            Console.WriteLine ("\nCheck whether MyTypeDemoClass can be hosted in a context.");
            if( myType.IsContextful)
            {
                Console.WriteLine(typeof(MyTypeDemoClass) + " can be hosted in a context.");
            }
            else
            {
                Console.WriteLine(typeof(MyTypeDemoClass) + " cannot be hosted in a context.");
            }
        }
        catch( Exception e )
        {
            Console.WriteLine("Exception: {0}", e.Message);
        }
    }
}
// This class demonstrates IsContextfulImpl.
public class MyContextBoundClass : ContextBoundObject
{
    public string myString = "This class is used to demonstrate members of the Type class.";
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

public __gc class MyTypeDelegatorClass : public TypeDelegator {
public:
   String* myElementType;
private:
   Type* myType;
public:
   MyTypeDelegatorClass(Type* myType) : TypeDelegator(myType) {
      this->myType = myType;
   }
   // Override IsContextfulImpl.
protected:
   bool IsContextfulImpl() {
      // Check whether the type is contextful.
      if (myType->IsContextful) {
         myElementType = S" is contextful ";
         return true;
      }
      return false;
   }
};

public __gc class MyTypeDemoClass {
};

// This class demonstrates IsContextfulImpl.
public __gc class MyContextBoundClass : public ContextBoundObject {
public:
   String* myString;
};

int main() {
   try {
      MyTypeDelegatorClass* myType;
      Console::WriteLine (S"Check whether MyContextBoundClass can be hosted in a context.");
      // Check whether MyContextBoundClass is contextful.
      myType = new MyTypeDelegatorClass(__typeof(MyContextBoundClass));
      if (myType->IsContextful) {
         Console::WriteLine(S"{0} can be hosted in a context.", __typeof(MyContextBoundClass));
      } else {
         Console::WriteLine(S"{0} cannot be hosted in a context.", __typeof(MyContextBoundClass));
      }
      // Check whether the int type is contextful.
      myType = new MyTypeDelegatorClass(__typeof(MyTypeDemoClass));
      Console::WriteLine (S"\nCheck whether MyTypeDemoClass can be hosted in a context.");
      if (myType->IsContextful) {
         Console::WriteLine(S"{0} can be hosted in a context.", __typeof(MyTypeDemoClass));
      } else {
         Console::WriteLine(S"{0} cannot be hosted in a context.", __typeof(MyTypeDemoClass));
      }
   } catch (Exception* e) {
      Console::WriteLine(S"Exception: {0}", e->Message);
   }
}

[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 ファミリ

参照

Type クラス | Type メンバ | System 名前空間 | IsContextful