Partager via


IVsDataProviderObjectFactory.CreateObject, méthode

Crée une instance de l'entité spécifiée en charge de DDEX implémentée par le fournisseur de DDEX.

Espace de noms :  Microsoft.VisualStudio.Data.Core
Assembly :  Microsoft.VisualStudio.Data.Core (dans Microsoft.VisualStudio.Data.Core.dll)

Syntaxe

'Déclaration
Function CreateObject ( _
    objType As Type _
) As Object
Object CreateObject(
    Type objType
)
Object^ CreateObject(
    Type^ objType
)
abstract CreateObject : 
        objType:Type -> Object 
function CreateObject(
    objType : Type
) : Object

Paramètres

  • objType
    Type : System.Type
    Un type d'entité de prise en charge DDEX.

Valeur de retour

Type : System.Object
Une instance de l'entité spécifiée en charge de DDEX implémentée par le fournisseur de DDEX, si le fournisseur de DDEX le prend en charge ; sinon, nullune référence null (Nothing en Visual Basic).

Exceptions

Exception Condition
ArgumentNullException

Le paramètre objType est nullune référence null (Nothing en Visual Basic).

Notes

Probablement la méthode la plus importante dans la plateforme de DDEX, cette méthode représente le cœur du modèle d'extensibilité, ce qui permet un type abstrait (par exemple, une interface ou une classe de base) à passer au fournisseur et l'obtention arrière à l'implémentation d'un fournisseur de ce type.Un fournisseur applique cette méthode pour retourner des entités de niveau supérieur de charge, c. autrement dit., celles généralement créées directement par un client et non indirectement par à interroger une connexion de données pour un service ou à créer un type qui est référencé à partir d'un fichier XML de prise en charge de données.

Exemples

Le code suivant montre comment appliquer cette méthode pour créer un certain nombre d'entités standard de charge.L'exemple hérite de la classe d' DataProviderObjectFactory d'infrastructure, qui fournit une implémentation par défaut des méthodes d' GetType et d' GetAssembly .

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() {}

}

Sécurité .NET Framework

Voir aussi

Référence

IVsDataProviderObjectFactory Interface

Microsoft.VisualStudio.Data.Core, espace de noms