本文整理汇总了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.";
}