ImportedFromTypeLibAttribute Класс

Определение

Показывает, что определенные в сборке типы были исходно определены в библиотеке типов.

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
Наследование
ImportedFromTypeLibAttribute
Атрибуты

Примеры

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

Комментарии

Этот атрибут можно применить к сборкам, хотя Tlbimp.exe (средство импорта библиотек типов) обычно применяет его при использовании библиотеки типов.

Основное использование атрибута заключается в захвате исходного источника сведений о типе. Например, можно импортировать A.tlb в качестве сборки взаимодействия, которая называется A.dll, и иметь ссылку B.dll сборки A.dll. При экспорте B.dll в B.tlb этот атрибут вызывает ссылки в B.tlb, указывающие на A.dll вместо A.tlb. Это не следует путать с ComImportAttributeтем, что указывает, что отдельный тип реализован в COM.

Конструкторы

ImportedFromTypeLibAttribute(String)

Инициализирует новый экземпляр класса ImportedFromTypeLibAttribute с именем файла исходной библиотеки типов.

Свойства

TypeId

В случае реализации в производном классе возвращает уникальный идентификатор для этого атрибута Attribute.

(Унаследовано от Attribute)
Value

Возвращает местоположение файла исходной библиотеки типов.

Методы

Equals(Object)

Возвращает значение, показывающее, равен ли экземпляр указанному объекту.

(Унаследовано от Attribute)
GetHashCode()

Возвращает хэш-код данного экземпляра.

(Унаследовано от Attribute)
GetType()

Возвращает объект Type для текущего экземпляра.

(Унаследовано от Object)
IsDefaultAttribute()

При переопределении в производном классе указывает, является ли значение этого экземпляра значением по умолчанию для производного класса.

(Унаследовано от Attribute)
Match(Object)

При переопределении в производном классе возвращает значение, указывающее, является ли этот экземпляр равным заданному объекту.

(Унаследовано от Attribute)
MemberwiseClone()

Создает неполную копию текущего объекта Object.

(Унаследовано от Object)
ToString()

Возвращает строку, представляющую текущий объект.

(Унаследовано от Object)

Явные реализации интерфейса

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

Сопоставляет набор имен соответствующему набору идентификаторов диспетчеризации.

(Унаследовано от Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Возвращает сведения о типе объекта, которые можно использовать для получения сведений о типе интерфейса.

(Унаследовано от Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Возвращает количество предоставляемых объектом интерфейсов для доступа к сведениям о типе (0 или 1).

(Унаследовано от Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Предоставляет доступ к открытым свойствам и методам объекта.

(Унаследовано от Attribute)

Применяется к

См. также раздел