Compartir a través de


Clase ImportedFromTypeLibAttribute

 

Publicado: octubre de 2016

Indica que los tipos definidos dentro de un ensamblado se definieron originalmente en una biblioteca de tipos.

Espacio de nombres:   System.Runtime.InteropServices
Ensamblado:  mscorlib (en mscorlib.dll)

Jerarquía de herencia

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

Sintaxis

[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

Constructores

Nombre Descripción
System_CAPS_pubmethod ImportedFromTypeLibAttribute(String)

Inicializa una nueva instancia de la ImportedFromTypeLibAttribute clase con el nombre del archivo de biblioteca de tipos original.

Propiedades

Nombre Descripción
System_CAPS_pubproperty TypeId

Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.(Heredado de Attribute).

System_CAPS_pubproperty Value

Obtiene el nombre del archivo de biblioteca de tipos original.

Métodos

Nombre Descripción
System_CAPS_pubmethod Equals(Object)

Esta API admite la infraestructura producto y no está diseñada para usarse directamente desde el código. Devuelve un valor que indica si esta instancia es igual que un objeto especificado.(Heredado de Attribute).

System_CAPS_pubmethod GetHashCode()

Devuelve el código hash de esta instancia.(Heredado de Attribute).

System_CAPS_pubmethod GetType()

Obtiene el Type de la instancia actual.(Heredado de Object).

System_CAPS_pubmethod IsDefaultAttribute()

Si se reemplaza en una clase derivada, indica si el valor de esta instancia es el valor predeterminado de la clase derivada.(Heredado de Attribute).

System_CAPS_pubmethod Match(Object)

Cuando se invalida en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.(Heredado de Attribute).

System_CAPS_pubmethod ToString()

Devuelve una cadena que representa el objeto actual.(Heredado de Object).

Implementaciones de interfaz explícitas

Nombre Descripción
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.(Heredado de Attribute).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Obtiene la información de tipos de un objeto, que puede utilizarse para obtener la información de tipos de una interfaz.(Heredado de Attribute).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).(Heredado de Attribute).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Proporciona acceso a las propiedades y los métodos expuestos por un objeto.(Heredado de Attribute).

Comentarios

Este atributo se puede aplicar a ensamblados, aunque el Tlbimp.exe (Type Library Importer) normalmente se aplica automáticamente cuando se una biblioteca de tipos.

El uso del atributo principal es capturar el origen inicial de la información de tipo. Por ejemplo, puede importar A.tlb. como un ensamblado de interoperabilidad denominado A.dll y tiene B.dll referencia.dll de ensamblado. Al exportar B.dll a B.tlb, este atributo hace que las referencias de B.tlb que señalan a A.dll a A.tlb.. No debe confundirse con el ComImportAttribute, que especifica que un tipo individual se implementa en COM.

Ejemplos

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;
   }
};

Información de versión

.NET Framework
Disponible desde 1.1

Seguridad para subprocesos

Cualquier miembro ( Compartido en Visual Basic) estático público de este tipo es seguro para subprocesos. No se garantiza que los miembros de instancia sean seguros para subprocesos.

Ver también

ComImportAttribute
Espacio de nombres System.Runtime.InteropServices
Tlbimp.exe (Type Library Importer)

Volver al principio