要求に応じてサービスのインスタンスを作成できるコールバック機構を提供します。
名前空間: System.ComponentModel.Design
アセンブリ: System (system.dll 内)
構文
'宣言
<ComVisibleAttribute(True)> _
Public Delegate Function ServiceCreatorCallback ( _
container As IServiceContainer, _
serviceType As Type _
) As Object
'使用
Dim instance As New ServiceCreatorCallback(AddressOf HandlerMethod)
[ComVisibleAttribute(true)]
public delegate Object ServiceCreatorCallback (
IServiceContainer container,
Type serviceType
)
[ComVisibleAttribute(true)]
public delegate Object^ ServiceCreatorCallback (
IServiceContainer^ container,
Type^ serviceType
)
/** @delegate */
/** @attribute ComVisibleAttribute(true) */
public delegate Object ServiceCreatorCallback (
IServiceContainer container,
Type serviceType
)
JScript では、デリゲートは使用できますが、新規に宣言することはできません。
パラメータ
- container
サービスの作成を要求したサービス コンテナ。
- serviceType
作成するサービスの型。
戻り値
serviceType によって指定されたサービス。サービスが作成されなかった場合は null 参照 (Visual Basic では Nothing)。
解説
ServiceCreatorCallback は、デザイナの読み込み直後に作成されるサービスではなく、必要に応じて作成を要求できるサービスを発行するための機構を提供します。サービスが必須ではなく、使用されない可能性がある場合は、コールバック関数を使用できます。ServiceCreatorCallback を使用して発行されたサービスは、要求および作成されない限り、リソースを消費することもありません。コールバック関数を使用してサービスを発行するには、ServiceCreatorCallback を IServiceContainer の AddService メソッドに渡します。
注意
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、SharedState です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。
使用例
コールバック関数を使用してサービスを発行する方法を次のコード例で示します。
' The following code shows how to publish a service using a callback function.
' Creates a service creator callback.
Dim callback1 As New ServiceCreatorCallback _
(AddressOf myCallBackMethod)
' Adds the service using its type and the service creator.
serviceContainer.AddService(GetType(myService), callback1)
// The following code shows how to publish a service using a callback function.
// Creates a service creator callback.
ServiceCreatorCallback callback1 =
new ServiceCreatorCallback(myCallBackMethod);
// Adds the service using its type and the service creator callback.
serviceContainer.AddService(typeof(myService), callback1);
// The following code shows how to publish a service using a callback function.
// Creates a service creator callback.
ServiceCreatorCallback^ callback1 =
gcnew ServiceCreatorCallback( this, &Sample::myCallBackMethod );
// Adds the service using its type and the service creator callback.
serviceContainer->AddService( myService::typeid, callback1 );
// The following code shows how to publish a service using a
// callback function.
// Creates a service creator callback.
ServiceCreatorCallback callBack1 = new ServiceCreatorCallback(
MyCallBackMethod);
// Adds the service using its type and the service creator callback.
serviceContainer.AddService(MyService.class.ToType(), callBack1);
プラットフォーム
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
参照
関連項目
System.ComponentModel.Design 名前空間
AddService
IServiceContainer インターフェイス