Classe ImportedFromTypeLibAttribute
Dica
The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.
Indica que os tipos definidos dentro de um assembly foram originalmente definidos em uma biblioteca de tipos.
Namespace: System.Runtime.InteropServices
Assembly: mscorlib (em mscorlib.dll)
Hierarquia de Herança
System.Object
System.Attribute
System.Runtime.InteropServices.ImportedFromTypeLibAttribute
Sintaxe
[AttributeUsageAttribute(AttributeTargets.Assembly, Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class ImportedFromTypeLibAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly, Inherited = false)]
[ComVisibleAttribute(true)]
public ref class ImportedFromTypeLibAttribute sealed : Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Assembly, Inherited = false)>]
[<ComVisibleAttribute(true)>]
type ImportedFromTypeLibAttribute =
class
inherit Attribute
end
<AttributeUsageAttribute(AttributeTargets.Assembly, Inherited := False)>
<ComVisibleAttribute(True)>
Public NotInheritable Class ImportedFromTypeLibAttribute
Inherits Attribute
Construtores
Nome | Descrição | |
---|---|---|
ImportedFromTypeLibAttribute(String) | Inicializa uma nova instância da classe ImportedFromTypeLibAttribute com o nome do arquivo de biblioteca de tipo original. |
Propriedades
Nome | Descrição | |
---|---|---|
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
Nome | Descrição | |
---|---|---|
Equals(Object) | Esta API dá suporte à infraestrutura produto e não se destina a ser usada diretamente do seu código. Retorna um valor que indica se essa instância é igual a um objeto especificado.(Herdado de Attribute.) |
|
GetHashCode() | Retorna o código hash para essa instância.(Herdado de Attribute.) |
|
GetType() | ||
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.) |
|
ToString() | Retorna uma cadeia de caracteres que representa o objeto atual.(Herdado de Object.) |
Implementações Explícitas da Interface
Nome | Descrição | |
---|---|---|
_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.) |
Comentários
Você pode aplicar esse atributo para assemblies, embora o Tlbimp.exe (Importador de Biblioteca de Tipos) aplica normalmente para você quando ele uma biblioteca de tipos.
O principal uso do atributo é capturar a origem das informações de tipo. Por exemplo, você pode importar A.tlb como um assembly de interoperabilidade chamado. dll e ter o assembly de referência de b. dll. dll. Quando você exportar um b. dll para B.tlb, esse atributo faz as referências no B.tlb que apontam para o. dll em vez disso, aponte para A.tlb. Isso não deve ser confundido com o ComImportAttribute, que especifica se um tipo individual é implementado no COM.
Exemplos
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;
}
}
}
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 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;
}
};
Informações de Versão
.NET Framework
Disponível desde 1.1
Acesso thread-safe
Quaisquer membros estáticos públicos ( Compartilhado no Visual Basic) desse tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.
Confira Também
ComImportAttribute
Namespace System.Runtime.InteropServices
Tlbimp.exe (Importador de Biblioteca de Tipos)
Retornar ao início