Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Type.IsContextfulImpl Method

Implements the IsContextful property and determines whether the Type can be hosted in a context.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

'Declaration
Protected Overridable Function IsContextfulImpl As Boolean
'Usage
Dim returnValue As Boolean

returnValue = Me.IsContextfulImpl
protected boolean IsContextfulImpl ()
protected function IsContextfulImpl () : boolean

Return Value

true if the Type can be hosted in a context; otherwise, false.

This method can be overridden by a derived class.

A context intercepts calls to the class members and enforce policies that are applied to the class, such as synchronization.

The following example demonstrates a use of the IsContextfulImpl method.

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

import System.*;
import System.Reflection.*;

public class MyTypeDelegatorClass extends TypeDelegator
{
    public String myElementType = null;
    private Type myType = null;

    public MyTypeDelegatorClass(Type myType)
    {
        super(myType);
        this.myType = myType;
    } //MyTypeDelegatorClass

    // Override IsContextfulImpl.
    protected boolean IsContextfulImpl()
    {
        // Check whether the type is contextful.
        if (myType.get_IsContextful()) {
            myElementType = " is contextful ";
            return true;
        }
        return false;
    } //IsContextfulImpl
} //MyTypeDelegatorClass

public class MyTypeDemoClass
{
    public static void main(String[] args)
    {
        try {
            MyTypeDelegatorClass myType;
            Console.WriteLine("Check whether MyContextBoundClass can be hosted"
                + " in a context.");
            // Check whether MyContextBoundClass is contextful.
            myType = new MyTypeDelegatorClass(MyContextBoundClass.class.ToType());
            if (myType.get_IsContextful()) {
                Console.WriteLine(MyContextBoundClass.class.ToType() 
                    + " can be hosted in a context.");
            }
            else {
                Console.WriteLine(MyContextBoundClass.class.ToType() 
                    + " cannot be hosted in a context.");
            }
            // Check whether the int type is contextful.
            myType = new MyTypeDelegatorClass(MyTypeDemoClass.class.ToType());
            Console.WriteLine("\nCheck whether MyTypeDemoClass can be hosted" 
                + " in a context.");
            if (myType.get_IsContextful()) {
                Console.WriteLine(MyTypeDemoClass.class.ToType() 
                    + " can be hosted in a context.");
            }
            else {
                Console.WriteLine(MyTypeDemoClass.class.ToType() 
                    + " cannot be hosted in a context.");
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: {0}", e.get_Message());
        }
    } //main
} //MyTypeDemoClass

// This class demonstrates IsContextfulImpl.
public class MyContextBoundClass extends ContextBoundObject
{
    public String myString = "This class is used to demonstrate members of the" 
        + " Type class.";
} //MyContextBoundClass

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft