ImportedFromTypeLibAttribute Classe

Definição

Indica que os tipos definidos dentro de um assembly foram originalmente definidos em uma biblioteca de tipos.

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
Herança
ImportedFromTypeLibAttribute
Atributos

Exemplos

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

Comentários

Você pode aplicar esse atributo a assemblies, embora o Tlbimp.exe (Importador de Biblioteca de Tipos) normalmente o aplique para você quando ele é uma biblioteca de tipos.

O uso primário do atributo é capturar a fonte original das informações de tipo. Por exemplo, você pode importar A.tlb como um assembly de interoperabilidade chamado A.dll e ter o assembly B.dll referência A.dll. Quando você exporta B.dll para B.tlb, esse atributo faz com que as referências em B.tlb que apontam para A.dll apontem para A.tlb. Isso não deve ser confundido com o ComImportAttribute, que especifica que um tipo individual é implementado em COM.

Construtores

ImportedFromTypeLibAttribute(String)

Inicializa uma nova instância da classe ImportedFromTypeLibAttribute com o nome do arquivo de biblioteca de tipo original.

Propriedades

TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.

(Herdado de Attribute)
Value

Obtém o nome do arquivo de biblioteca de tipos original.

Métodos

Equals(Object)

Retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
GetHashCode()

Retorna o código hash para a instância.

(Herdado de Attribute)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.

(Herdado de Attribute)
Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

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

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornece acesso a propriedades e métodos expostos por um objeto.

(Herdado de Attribute)

Aplica-se a

Confira também