Type.IsContextfulImpl 메서드
IsContextful 속성을 구현하고, Type이 컨텍스트에서 호스팅될 수 있는지 여부를 확인합니다.
네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Protected Overridable Function IsContextfulImpl As Boolean
‘사용 방법
Dim returnValue As Boolean
returnValue = Me.IsContextfulImpl
protected virtual bool IsContextfulImpl ()
protected:
virtual bool IsContextfulImpl ()
protected boolean IsContextfulImpl ()
protected function IsContextfulImpl () : boolean
반환 값
Type이 컨텍스트에서 호스팅될 수 있으면 true이고, 그렇지 않으면 false입니다.
설명
이 메서드는 파생된 클래스에서 재정의할 수 있습니다.
컨텍스트에서는 클래스 멤버에 대한 호출을 가로채서 해당 클래스에 적용되는 동기화 등의 정책을 적용합니다.
예제
다음 예제에서는 IsContextfulImpl 메서드의 사용법을 설명합니다.
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
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.";
}
using namespace System;
using namespace System::Reflection;
public ref class MyTypeDelegatorClass: public TypeDelegator
{
public:
String^ myElementType;
private:
Type^ myType;
public:
MyTypeDelegatorClass( Type^ myType )
: TypeDelegator( myType )
{
this->myType = myType;
}
protected:
// Override IsContextfulImpl.
virtual bool IsContextfulImpl() override
{
// Check whether the type is contextful.
if ( myType->IsContextful )
{
myElementType = " is contextful ";
return true;
}
return false;
}
};
public ref class MyTypeDemoClass{};
// This class demonstrates IsContextfulImpl.
public ref class MyContextBoundClass: public ContextBoundObject
{
public:
String^ myString;
};
int main()
{
try
{
MyTypeDelegatorClass^ myType;
Console::WriteLine( "Check whether MyContextBoundClass can be hosted in a context." );
// Check whether MyContextBoundClass is contextful.
myType = gcnew MyTypeDelegatorClass( MyContextBoundClass::typeid );
if ( myType->IsContextful )
{
Console::WriteLine( "{0} can be hosted in a context.", MyContextBoundClass::typeid );
}
else
{
Console::WriteLine( "{0} cannot be hosted in a context.", MyContextBoundClass::typeid );
}
myType = gcnew MyTypeDelegatorClass( MyTypeDemoClass::typeid );
Console::WriteLine( "\nCheck whether MyTypeDemoClass can be hosted in a context." );
if ( myType->IsContextful )
{
Console::WriteLine( "{0} can be hosted in a context.", MyTypeDemoClass::typeid );
}
else
{
Console::WriteLine( "{0} cannot be hosted in a context.", MyTypeDemoClass::typeid );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception: {0}", e->Message );
}
}
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
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원