ImportedFromTypeLibAttribute 類別

定義

指示在組件內定義的型別原來是定義在型別程式庫中。

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
繼承
ImportedFromTypeLibAttribute
屬性

範例

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 中實作個別類型。

建構函式

ImportedFromTypeLibAttribute(String)

使用原始型別程式庫檔案 (Type Library File) 的名稱,初始化 ImportedFromTypeLibAttribute 類別的新執行個體。

屬性

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)
Value

取得原始型別程式庫檔案的名稱。

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱