为指定的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
类型:System.Guid
DDEX数据源标识符。
- command
类型:System.ComponentModel.Design.CommandID
标识操作的命令。
- context
类型:System.Object
表示操作存在的上下文的对象。
返回值
类型:System.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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。