Partager via


IVsDataSourceSpecializer Interface

Provides the ability to specialize DDEX provider implementations of support entities for specific data sources based on a data connection string.

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

Syntax

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

The IVsDataSourceSpecializer type exposes the following members.

Methods

  Name Description
Public method CreateObject Creates an instance of the specified DDEX support entity that is implemented by the DDEX provider for a specific DDEX data source.
Public method DeriveSource Derives a DDEX data source, when possible, from a DDEX provider-specific data connection string.
Public method GetAssembly Resolves a provider-specific assembly string to its corresponding Assembly representation, for a specific DDEX data source.
Public method GetType Resolves a provider-specific type name to its corresponding Type representation, for a specific DDEX data source.

Top

Remarks

A DDEX provider consists of a set of specific implementations of DDEX support entities that can be used by clients to invoke provider-specific behavior for a particular, well-known action. An implementation of the IVsDataProviderObjectFactory interface is used to create instances of these support entities. When a DDEX provider supports multiple DDEX data sources, the provider object factory mechanism can be extended to allow for different implementations of the same support entity depending on the data source being targeted.

This support entity enables this type of extension by accepting a specific DDEX data source identifier as an additional parameter when creating support entities. It also enables derivation of a DDEX data source from a data connection string that identifies the target data source, so a client can initially determine the intended DDEX data source. Additionally, it represents custom type and assembly resolution for specific DDEX data sources that you can use when working with support entities that specify this information as strings.

A DDEX provider may implement this support entity implicitly or explicitly. An implicit implementation occurs when the DDEX provider is registry based and a built-in implementation of the interface reads various registry keys that describe the different support entity implementations for each data source. An explicit implementation occurs when the DDEX provider is package based, or when it is registry based with a specification of how to create the support entity added to the registry. The former is agile; the latter supports only simple cases but is the most agile. A DDEX provider must decide which approach to take when implementing data source specialization.

Examples

The following code demonstrates how a DDEX provider can implement the IVsDataSourceSpecializer interface with support for multiple implementations of a standard support entity. It also shows a possible implementation of the DeriveSource method that is based on a simple connection string format. It uses the base implementation of the interface that is defined in the DDEX framework assembly.

using System;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Data.Framework;
using Microsoft.VisualStudio.Data.Services.SupportEntities;

internal class MySourceSpecializer : DataSourceSpecializer
{
    private static readonly Guid Source1Guid =
        new Guid("A871863D-7D71-4e49-A8C5-4E959DDE7AF7");
    private static readonly Guid Source2Guid =
        new Guid("D79D7D55-A266-4db9-92A9-3FDBA5D6A722");

    public override Guid DeriveSource(string connectionString)
    {
        if (connectionString.StartsWith("Source1"))
        {
            return Source1Guid;
        }
        if (connectionString.StartsWith("Source2"))
        {
            return Source2Guid;
        }
        return base.DeriveSource(connectionString);
    }

    public override object CreateObject(Guid source, Type objType)
    {
        if (objType == null)
        {
            throw new ArgumentNullException("objType");
        }
        if (objType == typeof(IVsDataConnectionProperties))
        {
            if (source == Source1Guid)
            {
                return new MySource1ConnectionProperties();
            }
            if (source == Source2Guid)
            {
                return new MySource2ConnectionProperties();
            }
        }
        return base.CreateObject(source, objType);
    }
}

internal class MySource1ConnectionProperties : DataConnectionProperties
{
}

internal class MySource2ConnectionProperties : DataConnectionProperties
{
}

See Also

Reference

Microsoft.VisualStudio.Data.Core Namespace