Share via


IVsDataSourceSpecializer.CreateObject Method

Creates an instance of the specified DDEX support entity that is implemented by the DDEX provider for a specific DDEX data source.

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

Syntax

'Declaration
Function CreateObject ( _
    source As Guid, _
    objType As Type _
) As Object
Object CreateObject(
    Guid source,
    Type objType
)
Object^ CreateObject(
    Guid source, 
    Type^ objType
)
abstract CreateObject : 
        source:Guid * 
        objType:Type -> Object 
function CreateObject(
    source : Guid, 
    objType : Type
) : Object

Parameters

  • source
    Type: System.Guid
    A DDEX data source identifier.
  • objType
    Type: System.Type
    A type of DDEX support entity.

Return Value

Type: System.Object
An instance of the specified DDEX support entity that is implemented by the DDEX provider for a specific DDEX data source, if the DDEX provider supports it; otherwise, nulla null reference (Nothing in Visual Basic).

Exceptions

Exception Condition
ArgumentNullException

The objType parameter is nulla null reference (Nothing in Visual Basic).

Remarks

This method allows a DDEX provider to create different implementations of a DDEX support entity, depending on which DDEX data source is currently being targeted by the DDEX client. One example of this occurs with the IVsDataConnectionUIControl support entity, which has two implementations in the Microsoft SQL Server DDEX provider: one for connecting to SQL Server by using a server name (the Microsoft SQL Server data source), and one for connecting to SQL Server Express Edition by using a database file name (the Microsoft SQL Server Database File data source).

Examples

The following code demonstrates how to implement this method to create one of the standard support entities for two different data sources. The example inherits from the framework DataSourceSpecializer class, which provides a default implementation of the other methods on the IVsDataSourceSpecializer interface.

C#

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

public class MySourceSpecializer2 : DataSourceSpecializer
{
    private static readonly Guid s_dataSource1 =
        new Guid("F24C1C71-D9AE-47ec-80C6-91B864201D72");
    private static readonly Guid s_dataSource2 =
        new Guid("194DD1D2-19A8-4493-A70B-F83C141D29E5");

    public override object CreateObject(Guid source, Type objType)
    {
        if (source == s_dataSource1)
        {
            if (objType == typeof(IVsDataConnectionUIControl))
            {
                return new MyConnectionUIControl1();
            }
        }
        if (source == s_dataSource2)
        {
            if (objType == typeof(IVsDataConnectionUIControl))
            {
                return new MyConnectionUIControl2();
            }
        }
        return null;
    }
}

internal class MyConnectionUIControl1 : DataConnectionUIControl
{
}

internal class MyConnectionUIControl2 : DataConnectionUIControl
{
}

.NET Framework Security

See Also

Reference

IVsDataSourceSpecializer Interface

Microsoft.VisualStudio.Data.Core Namespace