IVsDataProviderObjectFactory.CreateObject Method

Creates an instance of the specified DDEX support entity that is implemented by the DDEX provider.

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

Syntax

'Declaration
Function CreateObject ( _
    objType As Type _
) As Object
'Usage
Dim instance As IVsDataProviderObjectFactory 
Dim objType As Type 
Dim returnValue As Object 

returnValue = instance.CreateObject(objType)
Object CreateObject(
    Type objType
)
Object^ CreateObject(
    Type^ objType
)
function CreateObject(
    objType : Type
) : Object

Parameters

  • 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, 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

Probably the most important method in the DDEX platform, this method represents the core of the extensibility model, allowing an abstract type (for example, an interface or base class) to be passed to the provider and getting back a provider’s implementation of this type. A provider implements this method to return top-level support entities, that is, those normally created directly by a client as opposed to indirectly by querying a data connection for a service or creating a type that is referenced from a data support XML file.

Examples

The following code demonstrates how to implement this method to create a number of the standard support entities. The example inherits from the framework DataProviderObjectFactory class, which provides a default implementation of the GetType and GetAssembly methods.

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

internal class MyProviderObjectFactory : DataProviderObjectFactory
{
    public override object CreateObject(Type objType)
    {
        if (objType == null)
        {
            throw new ArgumentNullException("objType");
        }
        if (objType == typeof(IVsDataConnectionProperties))
        {
            return new MyConnectionProperties();
        }
        if (objType == typeof(IVsDataConnectionSupport))
        {
            return new MyConnectionSupport();
        }
        return null;
    }
}

internal class MyConnectionProperties : DataConnectionProperties
{
}

internal class MyConnectionSupport : IVsDataConnectionSupport
{
    // Implement the interface methods 

    public void Initialize(object providerObj) {}
    public bool Open(bool doPromptCheck) {return true;}
    public void Close() {}
    public string ConnectionString { get {return "";} set {} }
    public int ConnectionTimeout { get {return 0;} set {} }
    public DataConnectionState State { get {return DataConnectionState.Closed;} }
    public object ProviderObject { get {return null;} }

    // Inherited from System.IServiceProvider  
    public Object GetService(Type serviceType) {return null;}

    // Inherited from System.IDisposable 
    public void Dispose() {}

}

.NET Framework Security

See Also

Reference

IVsDataProviderObjectFactory Interface

IVsDataProviderObjectFactory Members

Microsoft.VisualStudio.Data.Core Namespace