IVsDataProviderDynamicSupport.IsOperationSupported 方法
為指定的 DDEX 資料來源判斷作業是否支援目前環境,。
命名空間: Microsoft.VisualStudio.Data.Core
組件: Microsoft.VisualStudio.Data.Core (在 Microsoft.VisualStudio.Data.Core.dll 中)
語法
'宣告
Function IsOperationSupported ( _
source As Guid, _
command As CommandID, _
context As Object _
) As Boolean
bool IsOperationSupported(
Guid source,
CommandID command,
Object context
)
bool IsOperationSupported(
Guid source,
CommandID^ command,
Object^ context
)
abstract IsOperationSupported :
source:Guid *
command:CommandID *
context:Object -> bool
function IsOperationSupported(
source : Guid,
command : CommandID,
context : Object
) : boolean
參數
source
類型:GuidDDEX 資料來源識別項。
command
類型:CommandID識別作業的命令。
context
類型:Object表示作業存在之內容的物件。
傳回值
類型:Boolean
true ,如果作業是以在目前環境的提供者支援,否則, false。
例外狀況
例外狀況 | 條件 |
---|---|
ArgumentNullException | command 參數為 nullnull 參考 (即 Visual Basic 中的 Nothing)。 |
ArgumentException | context 參數不為指定之作業的預期值。 |
備註
這個方法可讓提供者 DDEX 動態修改哪些作業提供給使用者,根據目前環境和特定內容在該環境中。 換句話說,提供者可以適用於目前電腦的組態,並加入支援 DDEX 提供者的要安裝的元件。 通常這個方法會啟用或停用支援視特定元件。會在電腦上的特定作業,例如一個指令碼引擎。
範例
下列程式碼將示範如何實作這個方法,在此案例中為其支援的連接節點的其中一個部署命令在資料總管,只有在特定的登錄機碼存在時,表示特定部署技術來安裝。
using System;
using System.ComponentModel.Design;
using Microsoft.Win32;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Data.Services;
public class MyProviderDynamicSupport2 : IVsDataProviderDynamicSupport
{
private static readonly CommandID DeployCommand =
new CommandID(new Guid("6535F307-2083-4cbb-B2FA-11F2DCD69DAF"), 25);
public bool IsProviderSupported
{
get
{
return true;
}
}
public bool IsSourceSupported(Guid source)
{
return true;
}
public bool IsOperationSupported(
Guid source, CommandID command, object context)
{
if (command == null)
{
throw new ArgumentNullException("command");
}
if (command.Equals(DeployCommand))
{
IVsDataExplorerConnection explorerConnection =
context as IVsDataExplorerConnection;
if (explorerConnection == null)
{
throw new ArgumentException();
}
RegistryKey key = Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Company\DeployTechnology");
if (key == null)
{
return false;
}
key.Close();
}
return true;
}
public string GetUnsupportedReason(
Guid source, CommandID command, object context)
{
if (command == null)
{
throw new ArgumentNullException("command");
}
if (command.Equals(DeployCommand) &&
!IsOperationSupported(source, command, context))
{
// Note: This string should be localized
return "In order to deploy a database you need to install our deployment technology.";
}
return null;
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。