Type.IsContextfulImpl (Método)
.NET Framework 3.5
Actualización: noviembre 2007
Implementa la propiedad IsContextful y determina si la clase Type puede hospedarse en un contexto.
Ensamblado: mscorlib (en mscorlib.dll)
En el siguiente ejemplo se muestra una de las formas de utilizar el método IsContextfulImpl.
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 Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.