Compartir a través de


IVsDataDefaultObject Interface

Represents the default implementation of a DDEX support entity.

Namespace:  Microsoft.VisualStudio.Data.Core
Assembly:  Microsoft.VisualStudio.Data.Core (in Microsoft.VisualStudio.Data.Core.dll)

Syntax

'Declaration
Public Interface IVsDataDefaultObject
public interface IVsDataDefaultObject
public interface class IVsDataDefaultObject
type IVsDataDefaultObject =  interface end
public interface IVsDataDefaultObject

Remarks

When a DDEX client calls the DDEX runtime to create an instance of a DDEX support entity for a particular provider, the provider is queried to determine whether it supports the entity, and, if it does, an instance is created and returned. If the provider does not support the entity, the call by default either throws an exception or returns nulla null reference (Nothing in Visual Basic), depending on the code path. However, in some cases, the owners of the DDEX support entity may have a reasonable default implementation that they want to supply to clients when a DDEX provider does not supply its own implementation, thus avoiding the error condition.

One example of this in practice is the IVsDataConnectionUIConnector support entity. This support entity contains a single method that is called to open a data connection from a UI context, such as a data connection dialog box. The typical use of this support entity is to add additional behavior, such as checking for the existence of the data connection target and prompting to create a new data store if it was not found. However, a reasonable default is to simply open the connection normally and do nothing special. By supplying this default implementation, client code is simplified because it no longer needs to separately handle the cases in which the provider does or does not implement this support entity, nor does it need to include its own fallback, default implementation.

DDEX support entities that have a reasonable default implementation should include the DataDefaultObjectAttribute attribute on the type representing the support entity. This attribute identifies a default class that implements this interface. When requested by a client, the DDEX runtime will create an instance of the default class if no provider implementation is available. The purpose of this interface is to enable the DDEX runtime and clients to determine whether a given instance of an object is a default implementation.

The IVsDataDefaultObject interface is primarily of interest to DDEX platform extenders, that is, those creating additional DDEX services and support entities.

Examples

The following code shows the definition of the IVsDataConnectionUIConnector support entity that declares a default object attribute. It is followed by the implementation of this default object.

using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Data.Services;

[DataDefaultObject("C58E1B8D-9723-40c8-8B11-9DDAF0B393BA")]
public interface IVsDataConnectionUIConnector
{
    void Connect(IVsDataConnection connection);
}

[Guid("C58E1B8D-9723-40c8-8B11-9DDAF0B393BA")]
internal class DefaultConnectionUIConnector
    : IVsDataConnectionUIConnector,
      IVsDataDefaultObject
{
    public void Connect(IVsDataConnection connection)
    {
        if (connection == null)
        {
            throw new ArgumentNullException("connection");
        }
        connection.Open();
    }
}

See Also

Reference

Microsoft.VisualStudio.Data.Core Namespace