Freigeben über


ImportedFromTypeLibAttribute-Klasse

Gibt an, dass die innerhalb einer Assembly definierten Typen ursprünglich in einer Typbibliothek definiert wurden.

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
<AttributeUsageAttribute(AttributeTargets.Assembly, Inherited:=False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class ImportedFromTypeLibAttribute
    Inherits Attribute
'Usage
Dim instance As ImportedFromTypeLibAttribute
[AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class ImportedFromTypeLibAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly, Inherited=false)] 
[ComVisibleAttribute(true)] 
public ref class ImportedFromTypeLibAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class ImportedFromTypeLibAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false) 
ComVisibleAttribute(true) 
public final class ImportedFromTypeLibAttribute extends Attribute

Hinweise

Sie können dieses Attribut auf Assemblys anwenden, obwohl es beim Importieren einer Typbibliothek normalerweise von Type Library Importer-Tool (Tlbimp.exe) automatisch angewendet wird.

Das Attribut wird hauptsächlich zum Aufzeichnen der ursprünglichen Quelle der Typinformationen verwendet. Beispielsweise können Sie A.tlb als Interop-Assembly A.dll importieren und Assembly B.dll auf A.dll verweisen lassen. Beim Exportieren von B.dll nach B.tlb bewirkt dieses Attribut, dass die Verweise in B.tlb, die auf A.dll verweisen, stattdessen auf A.tlb zeigen. Dies darf nicht mit ComImportAttribute verwechselt werden, womit angegeben wird, dass ein einzelner Typ in COM implementiert wird.

Beispiel

Imports System
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 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
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 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;
        }
    }
}
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;
   }
};
import System.*;
import System.Reflection.*;
import System.Runtime.InteropServices.*;

class ClassA
{
    public static boolean IsCOMAssembly(Assembly a)
    {
        Object asmAttributes[] = a.GetCustomAttributes(
            ImportedFromTypeLibAttribute.class.ToType(), true);

        if (asmAttributes.length > 0) {
            ImportedFromTypeLibAttribute imptlb 
                = (ImportedFromTypeLibAttribute)(asmAttributes.get_Item(0));
            String strImportedFrom = imptlb.get_Value();

            // Print out the the name of the DLL from which 
            // the assembly is imported.
            Console.WriteLine("Assembly " + a.get_FullName() 
                + " is imported from " + strImportedFrom);
            return true;
        }
        // This is not a COM assembly.
        Console.WriteLine("Assembly " + a.get_FullName() 
            + " is not imported from COM");
        return false;
    } //IsCOMAssembly
} //ClassA

Vererbungshierarchie

System.Object
   System.Attribute
    System.Runtime.InteropServices.ImportedFromTypeLibAttribute

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

ImportedFromTypeLibAttribute-Member
System.Runtime.InteropServices-Namespace
ComImportAttribute-Klasse

Weitere Ressourcen

Type Library Importer-Tool (Tlbimp.exe)