Share via


IVsDataSupportObject<T> Interface

Represents an object that was created based on reference information supplied in a data support XML stream.

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

Syntax

'Declaration
Public Interface IVsDataSupportObject(Of T As Class)
public interface IVsDataSupportObject<T>
where T : class
generic<typename T>
where T : ref class
public interface class IVsDataSupportObject
type IVsDataSupportObject<'T when 'T : not struct> =  interface end
JScript does not support generic types or methods.

Type Parameters

  • T
    The type of the parameter.

The IVsDataSupportObject<T> type exposes the following members.

Methods

  Name Description
Public method Invoke Invokes a method on the object with additional parameters not present in the method signature.

Top

Remarks

The DDEX architecture is mainly data driven for complex areas of extensibility, such as representing the data source as an object model or in a hierarchical view. To achieve this, a support entity has been created whose purpose is to return a stream of XML that matches a known schema to the caller. The caller then interprets this XML and uses it to control that area of extensibility.

As part of this approach, the stream of XML often contains references back to code in the form of managed type names. The consumer of the stream of XML uses the GetType method to resolve these names into actual types, and then creates instances of these types as appropriate. The XML schema surrounding the type reference often includes a set of parameters that may be passed to an instance, allowing the same type to be used under multiple circumstances.

One example of this in practice is the IVsDataObjectSelector support entity. This support entity is referenced from parts of the Data Object Support XML stream that specify information about data source object types, like tables or stored procedures. It would be possible to write a selector implementation that uses a single parameter indicating the underlying identifier of the type of object to retrieve, and then in the object support XML include the correct value for this parameter under the selector reference for each type.

The purpose of this interface is to enable passing of these parameters to methods on a support entity without having to add additional methods or parameters to enable this parameterized scenario. This is done by using a late-bound method call approach that is handled appropriately by the provider’s implementation. The interface defines a single Invoke method to which the caller passes the name of the method to invoke, its regular set of arguments, and a set of parameters to specialize the behavior of the method. The format of the parameters depends on the caller. For example, it is up to the Data Object Support XML schema to define both how to enter parameters in the XML and how these parameters will translate into the object array of parameters passed to the implementation.

Examples

The following code shows an example of Data Object Support XML that defines information about two data object types, including references to the single type that implements a DSRefBuilder service for these types. Following this is code implementing the IDSRefBuilder interface as a data support object. The XML passes different parameters for each type, and the selector implementation shows the selection of two different code paths, depending on the parameters. Note that in a more typical case, the parameter values will be used in a more generic fashion so that the code is not aware of specific values, for example in the case of passing parameters down to another API that does the work.

XML:

<Type name="Table">
    <Identifier>
        <Part name="Name" />
    </Identifier>
    <Properties>
        <Property name="Id" type="System.Int32" />
    </Properties>
    <Services>
        <Service type="IDSRefBuilder"
            implementationType="MyDSRefBuilder">
            <Parameters method="AppendToDSRef">
                <Parameter value="DSREFTYPE_TABLE" />
            </Parameters>
        </Service>
    </Services>
</Type>
<Type name="View">
    <Identifier>
        <Part name="Name" />
    </Identifier>
    <Properties>
        <Property name="Id" type="System.Int32" />
    </Properties>
    <Services>
        <Service type="IDSRefBuilder"
            implementationType="MyDSRefBuilder">
            <Parameters method="AppendToDSRef">
                <Parameter value="DSREFTYPE_VIEW" />
            </Parameters>
        </Service>
    </Services>
</Type>
using System;
using Microsoft.VisualStudio.Data.Core;
using Microsoft.VisualStudio.Data.Services.SupportEntities;
using Microsoft.VisualStudio.Data.Services.SupportEntities.Interop;

internal class MyDSRefBuilder : IDSRefBuilder,
    IVsDataSupportObject<IDSRefBuilder>
{
    public void AppendToDSRef(
        object dsRef, string typeName, object[] identifier)
    {
        AppendToDSRef(dsRef, typeName, identifier, null);
    }

    object IVsDataSupportObject<IDSRefBuilder>.Invoke(
        string name, object[] args, object[] parameters)
    {
        if (name == null)
        {
            throw new ArgumentNullException("name");
        }
        if (name.Equals("AppendToDSRef", StringComparison.Ordinal))
        {
            if (args == null || args.Length != 3)
            {
                throw new ArgumentException();
            }
            AppendToDSRef(args[0], args[1] as string,
                args[2] as object[], parameters);
            return null;
        }
        throw new ArgumentException();
    }

    private void AppendToDSRef(object dsRef,
        string typeName, object[] identifier, object[] parameters)
    {
        if (parameters == null || parameters.Length == 0)
        {
            throw new ArgumentException();
        }
        string dsRefType = parameters[0] as string;
        if (dsRefType.Equals("DSREFTYPE_TABLE"))
        {
            AppendTableToDSRef(dsRef, identifier);
        }
        else if (dsRefType.Equals("DSREFTYPE_VIEW"))
        {
            AppendViewToDSRef(dsRef, identifier);
        }
    }

    private void AppendTableToDSRef(object dsRef, object[] identifier)
    {
        // Append table
    }

    private void AppendViewToDSRef(object dsRef, object[] identifier)
    {
        // Append view
    }
}

See Also

Reference

Microsoft.VisualStudio.Data.Core Namespace