本文整理匯總了C#中System.Type.IsContextfulImpl方法的典型用法代碼示例。如果您正苦於以下問題:C# Type.IsContextfulImpl方法的具體用法?C# Type.IsContextfulImpl怎麽用?C# Type.IsContextfulImpl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Type
的用法示例。
在下文中一共展示了Type.IsContextfulImpl方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MyTypeDelegatorClass
//引入命名空間
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.";
}