クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
以前のバージョン
.NET Framework SDK 2.0
System.Reflection
Assembly クラス

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2005/.Net Framework 2.0

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
Assembly クラス

Assembly を定義します。このアセンブリは再利用でき、バージョン管理可能で自己記述型の共通言語ランタイム アプリケーションのビルド ブロックです。

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)

Visual Basic (宣言)
<SerializableAttribute> _
<ClassInterfaceAttribute(ClassInterfaceType.None)> _
<ComVisibleAttribute(True)> _
Public Class Assembly
    Implements _Assembly, IEvidenceFactory, ICustomAttributeProvider, ISerializable
Visual Basic (使用法)
Dim instance As Assembly
C#
[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType.None)] 
[ComVisibleAttribute(true)] 
public class Assembly : _Assembly, IEvidenceFactory, ICustomAttributeProvider, 
    ISerializable
C++
[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType::None)] 
[ComVisibleAttribute(true)] 
public ref class Assembly : _Assembly, IEvidenceFactory, ICustomAttributeProvider, 
    ISerializable
J#
/** @attribute SerializableAttribute() */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.None) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class Assembly implements _Assembly, IEvidenceFactory, 
    ICustomAttributeProvider, ISerializable
JScript
SerializableAttribute 
ClassInterfaceAttribute(ClassInterfaceType.None) 
ComVisibleAttribute(true) 
public class Assembly implements _Assembly, IEvidenceFactory, 
    ICustomAttributeProvider, ISerializable

アセンブリは、インフラストラクチャを用意します。このインフラストラクチャによって、Runtime がアプリケーションの内容を完全に理解し、アプリケーションで定義されるバージョン管理と依存関係の規則を適用できます。これらは、バージョン管理の問題を解決し、Runtime アプリケーションの配置を単純化するために重要な概念です。

アセンブリ内の各メソッドについて、メソッド シグネチャを列挙するコード例を次に示します。

Visual Basic
' 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 
C#
// 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);
            }
        }
    }
}
Visual Basic
' 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
C#
// 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");
    }
}
C++
// 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
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker