IVsDataProviderObjectFactory.CreateObject 方法

创建指定的DDEX的实例支持由DDEX提供程序实现的实体。

命名空间:  Microsoft.VisualStudio.Data.Core
程序集:  Microsoft.VisualStudio.Data.Core(在 Microsoft.VisualStudio.Data.Core.dll 中)

语法

声明
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

参数

  • objType
    类型:System.Type
    DDEX的类型支持实体。

返回值

类型:System.Object
指定的DDEX的实例支持由DDEX提供程序实现的实体,则为; DDEX提供程序支持它;否则,nullnull 引用(在 Visual Basic 中为 Nothing)。

异常

异常 条件
ArgumentNullException

objType 参数为 nullnull 引用(在 Visual Basic 中为 Nothing)。

备注

可能的最重要的方法在DDEX平台,此方法表示扩展性模型的核心,允许抽象类型(例如,接口或基类)传递给提供程序并取回此类型的提供程序的实现。提供程序实现此方法返回顶级支持实体,也就是说,取消直接客户端通常创建的那些使用查询服务的数据连接或创建从数据中引用的类型相对支持XML文件。

示例

下面的代码演示如何实现此方法创建许多标准的支持实体。此示例从结构 DataProviderObjectFactory 选件类继承,提供 GetTypeGetAssembly 方法的默认实现。

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 安全性

请参见

参考

IVsDataProviderObjectFactory 接口

Microsoft.VisualStudio.Data.Core 命名空间