ImportedFromTypeLibAttribute 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指示在組件內定義的型別原來是定義在型別程式庫中。
public ref class ImportedFromTypeLibAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)]
public sealed class ImportedFromTypeLibAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ImportedFromTypeLibAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)>]
type ImportedFromTypeLibAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ImportedFromTypeLibAttribute = class
inherit Attribute
Public NotInheritable Class ImportedFromTypeLibAttribute
Inherits Attribute
- 繼承
- 屬性
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
class ClassA
{
private:
static bool IsCOMAssembly( Assembly^ a )
{
array<Object^>^AsmAttributes = a->GetCustomAttributes( ImportedFromTypeLibAttribute::typeid, true );
if ( AsmAttributes->Length > 0 )
{
ImportedFromTypeLibAttribute^ imptlb = dynamic_cast<ImportedFromTypeLibAttribute^>(AsmAttributes[ 0 ]);
String^ strImportedFrom = imptlb->Value;
// Print out the name of the DLL from which the assembly is imported.
Console::WriteLine( "Assembly {0} is imported from {1}", a->FullName, strImportedFrom );
return true;
}
// This is not a COM assembly.
Console::WriteLine( "Assembly {0} is not imported from COM", a->FullName );
return false;
}
};
using System;
using System.Reflection;
using System.Runtime.InteropServices;
namespace A
{
class ClassA
{
public static bool IsCOMAssembly(Assembly a)
{
object[] AsmAttributes = a.GetCustomAttributes(typeof(ImportedFromTypeLibAttribute), true);
if (AsmAttributes.Length > 0)
{
ImportedFromTypeLibAttribute imptlb = (ImportedFromTypeLibAttribute)AsmAttributes[0];
string strImportedFrom = imptlb.Value;
// Print out the name of the DLL from which the assembly is imported.
Console.WriteLine("Assembly " + a.FullName + " is imported from " + strImportedFrom);
return true;
}
// This is not a COM assembly.
Console.WriteLine("Assembly " + a.FullName + " is not imported from COM");
return false;
}
}
}
Imports System.Reflection
Imports System.Runtime.InteropServices
Module A
Public Function IsCOMAssembly(ByVal a As System.Reflection.Assembly) As Boolean
Dim AsmAttributes As Object() = a.GetCustomAttributes(GetType(ImportedFromTypeLibAttribute), True)
If AsmAttributes.Length = 1 Then
Dim imptlb As ImportedFromTypeLibAttribute = AsmAttributes(0)
Dim strImportedFrom As String = imptlb.Value
' Print out the name of the DLL from which the assembly is imported.
Console.WriteLine("Assembly " + a.FullName + " is imported from " + strImportedFrom)
Return True
End If
' This is not a COM assembly.
Console.WriteLine("Assembly " + a.FullName + " is not imported from COM")
Return False
End Function
End Module
您可以將此屬性套用至元件,不過 Tlbimp.exe (類型庫匯入工具) 通常會在類型庫時為您套用它。
屬性的主要用法是擷取類型資訊的原始來源。 例如,您可以將 A.tlb 匯入為稱為 A.dll 的 Interop 元件,並具有元件 B.dll 參考 A.dll。 當您將 B.dll 匯出至 B.tlb 時,這個屬性會導致 B.tlb 中的參考指向 A.dll 改為指向 A.tlb。 這不應該與 ComImportAttribute混淆,這會指定在 COM 中實作個別類型。
Imported |
使用原始型別程式庫檔案 (Type Library File) 的名稱,初始化 ImportedFromTypeLibAttribute 類別的新執行個體。 |
Equals(Object) |
傳回值,這個值指出此執行個體是否與指定的物件相等。 (繼承來源 Attribute) |
Get |
傳回這個執行個體的雜湊碼。 (繼承來源 Attribute) |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Is |
在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。 (繼承來源 Attribute) |
Match(Object) |
在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。 (繼承來源 Attribute) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
傳回代表目前物件的字串。 (繼承來源 Object) |
_Attribute. |
將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。 (繼承來源 Attribute) |
_Attribute. |
擷取物件的類型資訊,可以用來取得介面的類型資訊。 (繼承來源 Attribute) |
_Attribute. |
擷取物件提供的類型資訊介面數目 (0 或 1)。 (繼承來源 Attribute) |
_Attribute. |
提供物件所公開的屬性和方法的存取權。 (繼承來源 Attribute) |
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.1 |