Export (0) Print
Expand All
Expand Minimize

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)

protected virtual bool IsContextfulImpl ()
protected boolean IsContextfulImpl ()
protected function IsContextfulImpl () : boolean
Not applicable.

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.

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.";
}

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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft