다음을 통해 공유


Assembly 클래스

다시 사용 및 버전 지정이 가능한, 공용 언어 런타임 응용 프로그램의 자체 설명 빌딩 블록인 Assembly를 정의합니다.

네임스페이스: System.Reflection
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<SerializableAttribute> _
<ClassInterfaceAttribute(ClassInterfaceType.None)> _
<ComVisibleAttribute(True)> _
Public Class Assembly
    Implements _Assembly, IEvidenceFactory, ICustomAttributeProvider, ISerializable
‘사용 방법
Dim instance As Assembly
[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType.None)] 
[ComVisibleAttribute(true)] 
public class Assembly : _Assembly, IEvidenceFactory, ICustomAttributeProvider, 
    ISerializable
[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType::None)] 
[ComVisibleAttribute(true)] 
public ref class Assembly : _Assembly, IEvidenceFactory, ICustomAttributeProvider, 
    ISerializable
/** @attribute SerializableAttribute() */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.None) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class Assembly implements _Assembly, IEvidenceFactory, 
    ICustomAttributeProvider, ISerializable
SerializableAttribute 
ClassInterfaceAttribute(ClassInterfaceType.None) 
ComVisibleAttribute(true) 
public class Assembly implements _Assembly, IEvidenceFactory, 
    ICustomAttributeProvider, ISerializable

설명

어셈블리는 런타임에 응용 프로그램의 콘텐츠를 완전히 이해하고 이 응용 프로그램이 정의하는 버전 관리 및 종속성 규칙을 적용할 수 있도록 해 주는 인프라를 제공합니다. 이러한 개념은 버전 관리 문제를 해결하고 런타임 응용 프로그램의 배포를 단순화하는 데 중요합니다.

예제

다음 코드 예제에서는 어셈블리의 각 메서드에 대한 메서드 시그니처 목록을 표시합니다.

' LoadInvoke loads MyAssembly.dll and lists the method
' information for each method. After compiling this class,
' run LoadInvoke.exe with the DisplayName for the assembly,
' as shown here:
' LoadInvoke MyAssembly
Imports System
Imports System.Reflection
Imports System.Security.Permissions

Public Class LoadInvoke

    <PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
    Public Shared Sub Main(ByVal args() As String)
        Dim a As [Assembly] = [Assembly].Load(args(0))
        Dim mytypes As Type() = a.GetTypes()
        Dim flags As BindingFlags = BindingFlags.NonPublic Or BindingFlags.Public Or BindingFlags.Static Or _
            BindingFlags.Instance Or BindingFlags.DeclaredOnly

        Dim t As Type
        For Each t In mytypes
            Dim mi As MethodInfo() = t.GetMethods(flags)
            Dim obj As [Object] = Activator.CreateInstance(t)

            Dim m As MethodInfo
            For Each m In mi
                ' Instead of invoking the methods,
                ' it's safer to initially just list them.
                Console.WriteLine(m)
            Next m
        Next t
    End Sub 
End Class 
// LoadInvoke loads MyAssembly.dll and lists the method
// information for each method. After compiling this class,
// run LoadInvoke.exe with the DisplayName for the assembly,
// as shown here:
// LoadInvoke MyAssembly

using System;
using System.Reflection;
using System.Security.Permissions;

public class LoadInvoke
{
    [PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")]
    public static void Main(string[] args)
    {
        Assembly a = Assembly.Load(args[0]);
        Type[] mytypes = a.GetTypes();
        BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
            BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);

        foreach(Type t in mytypes)
        {
            MethodInfo[] mi = t.GetMethods(flags);
            Object obj = Activator.CreateInstance(t);

            foreach(MethodInfo m in mi)
            {
                // Instead of invoking the methods,
                // it's safer to initially just list them.
                Console.WriteLine(m);
            }
        }
    }
}
' Use this class with the LoadInvoke program.
' Compile this class using vbc /t:library MyAssembly.vb
' to obtain MyAssembly.dll.
Imports System
Imports Microsoft.VisualBasic

Public Class MyAssembly
    Public Sub MyMethod1()
        Console.WriteLine("Invoking MyAssembly.MyMethod1")
    End Sub 'MyMethod1
End Class 'MyAssembly
// Use this class with the LoadInvoke program.
// Compile this class using "csc /t:library MyAssembly.cs"
// to build MyAssembly.dll.
using System;

public class MyAssembly
{
    public void MyMethod1()
    {
        Console.WriteLine("This is MyMethod1");
    }
    public void MyMethod2()
    {
        Console.WriteLine("This is MyMethod2");
    }
    public void MyMethod3()
    {
        Console.WriteLine("This is MyMethod3");
    }
}
// Use this class with the LoadInvoke program.
// Compile this class using csc /t:library MyAssembly.cs
// to obtain MyAssembly.dll.
using namespace System;
public ref class MyAssembly
{
public:
   void MyMethod1()
   {
      Console::WriteLine( "Invoking MyAssembly.MyMethod1" );
   }

};

상속 계층 구조

System.Object
  System.Reflection.Assembly
     System.Reflection.Emit.AssemblyBuilder

스레드로부터의 안전성

이 형식은 다중 스레드 작업을 수행하는 데 안전합니다.

플랫폼

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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Assembly 멤버
System.Reflection 네임스페이스