ImportedFromTypeLibAttribute Třída

Definice

Označuje, že typy definované v rámci sestavení byly původně definovány v knihovně typů.

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
Dědičnost
ImportedFromTypeLibAttribute
Atributy

Příklady

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

Poznámky

Tento atribut můžete použít u sestavení, i když Tlbimp.exe (Type Library Importer) ho obvykle použije pro vás, když je knihovna typů.

Primárním použitím atributu je zachytit původní zdroj informací o typu. Můžete například importovat A.tlb jako sestavení zprostředkovatele komunikace s názvem A.dll a mít B.dll odkaz na sestavení A.dll. Při exportu B.dll do nástroje B.tlb tento atribut způsobí odkazy v nástroji B.tlb, které odkazují na A.dll odkazovat místo na A.tlb. To by nemělo být zaměňováno s ComImportAttribute, který určuje, že jednotlivý typ je implementován v modelu COM.

Konstruktory

ImportedFromTypeLibAttribute(String)

Inicializuje novou instanci ImportedFromTypeLibAttribute třídy s názvem původního souboru knihovny typů.

Vlastnosti

TypeId

Při implementaci v odvozené třídě získá jedinečný identifikátor pro tento Attribute.

(Zděděno od Attribute)
Value

Získá název původního souboru knihovny typů.

Metody

Equals(Object)

Vrací hodnotu, která určuje, zda je tato instance rovna zadanému objektu.

(Zděděno od Attribute)
GetHashCode()

Vrátí hodnotu hash pro tuto instanci.

(Zděděno od Attribute)
GetType()

Type Získá aktuální instanci.

(Zděděno od Object)
IsDefaultAttribute()

Při přepsání v odvozené třídě určuje, zda hodnota této instance je výchozí hodnotou odvozené třídy.

(Zděděno od Attribute)
Match(Object)

Při přepsání v odvozené třídě vrátí hodnotu, která označuje, zda se tato instance rovná zadanému objektu.

(Zděděno od Attribute)
MemberwiseClone()

Vytvoří použádnou kopii aktuálního souboru Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

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

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, který lze použít k získání informací o typu rozhraní.

(Zděděno od Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od Attribute)

Platí pro

Viz také