Export (0) Print
Expand All

ImportedFromTypeLibAttribute Class

Indicates that the types defined within an assembly were originally defined in a type library.

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)

[AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class ImportedFromTypeLibAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class ImportedFromTypeLibAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Assembly, Inherited=false) 
ComVisibleAttribute(true) 
public final class ImportedFromTypeLibAttribute extends Attribute

You can apply this attribute to assemblies, although the Type Library Importer (Tlbimp.exe) typically applies it for you when it a type library.

The primary use of the attribute is to capture the original source of the type information. For example, you can import A.tlb as an interop assembly called A.dll and have assembly B.dll reference A.dll. When you export B.dll to B.tlb, this attribute causes the references in B.tlb that point to A.dll to point instead to A.tlb. This should not be confused with the ComImportAttribute, which specifies that an individual type is implemented in COM.

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

import System.*;
import System.Reflection.*;
import System.Runtime.InteropServices.*;

class ClassA
{
    public static boolean IsCOMAssembly(Assembly a)
    {
        Object asmAttributes[] = a.GetCustomAttributes(
            ImportedFromTypeLibAttribute.class.ToType(), true);

        if (asmAttributes.length > 0) {
            ImportedFromTypeLibAttribute imptlb 
                = (ImportedFromTypeLibAttribute)(asmAttributes.get_Item(0));
            String strImportedFrom = imptlb.get_Value();

            // Print out the the name of the DLL from which 
			// the assembly is imported.
            Console.WriteLine("Assembly " + a.get_FullName() 
                + " is imported from " + strImportedFrom);
            return true;
        }
        // This is not a COM assembly.
        Console.WriteLine("Assembly " + a.get_FullName() 
            + " is not imported from COM");
        return false;
    } //IsCOMAssembly
} //ClassA

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft