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 平台上,這個方法表示擴充性模型的核心,允許抽象型別 (例如,介面或基底類別 (Base Class) 傳遞給提供者並且取回這個型別的提供者實作。提供者會實作這個方法會傳回最上層的實體,也就是說,間接直接用戶端通常與所建立的查詢服務的資料連接或的資料建立支援 XML 檔案參考型別相反。
範例
下列程式碼將示範如何實作這個方法建立一些標準支援實體。這個範例會從框架 DataProviderObjectFactory 類別繼承,提供 GetType 和 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() {}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。