共用方式為


IVsDataProviderDynamicSupport.GetUnsupportedReason 方法

取得描述作業不受支援的原因,執行指定的 DDEX 資料來源的當地語系化字串。

命名空間:  Microsoft.VisualStudio.Data.Core
組件:  Microsoft.VisualStudio.Data.Core (在 Microsoft.VisualStudio.Data.Core.dll 中)

語法

'宣告
Function GetUnsupportedReason ( _
    source As Guid, _
    command As CommandID, _
    context As Object _
) As String
string GetUnsupportedReason(
    Guid source,
    CommandID command,
    Object context
)
String^ GetUnsupportedReason(
    Guid source, 
    CommandID^ command, 
    Object^ context
)
abstract GetUnsupportedReason : 
        source:Guid * 
        command:CommandID * 
        context:Object -> string 
function GetUnsupportedReason(
    source : Guid, 
    command : CommandID, 
    context : Object
) : String

參數

  • source
    型別:System.Guid
    DDEX 資料來源識別項。
  • context
    型別:System.Object
    表示作業存在之內容的物件。

傳回值

型別:System.String
描述指定的作業失敗的當地語系化字串不支援,則為,如果作業實際上不支援物件;否則, nullNull 參照 (即 Visual Basic 中的 Nothing)。

例外狀況

例外狀況 條件
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 安全性

請參閱

參考

IVsDataProviderDynamicSupport 介面

Microsoft.VisualStudio.Data.Core 命名空間