次の方法で共有


Assembly クラス

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

この型のすべてのメンバの一覧については、Assembly メンバ を参照してください。

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

<Serializable>
<ClassInterface(ClassInterfaceType.AutoDual)>
Public Class Assembly   Implements IEvidenceFactory, ICustomAttributeProvider, _   ISerializable
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Assembly : IEvidenceFactory,   ICustomAttributeProvider, ISerializable
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDual)]
public __gc class Assembly : public IEvidenceFactory,   ICustomAttributeProvider, ISerializable
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDual)
class Assembly implements IEvidenceFactory,   ICustomAttributeProvider, ISerializable

スレッドセーフ

この型は、マルチスレッド操作に対して安全です。

解説

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

使用例

 
' LoadInvoke loads MyAssembly.dll and invokes the MyMethod1 method. 
' After compiling this class, run LoadInvoke.exe with MyAssembly.dll 
' as the command line argument, as shown below:
' LoadInvoke Myassembly.dll
Imports System
Imports System.Reflection


Public Class LoadInvoke
    Public Shared Sub Main(ByVal args() As String)
        Dim a As [Assembly] = [Assembly].LoadFrom(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
                m.Invoke(obj, Nothing)
            Next m
        Next t
    End Sub 'Main
End Class 'LoadInvoke

[C#] 
// LoadInvoke loads MyAssembly.dll and invokes the MyMethod1 method. 
// After compiling this class, run LoadInvoke.exe with MyAssembly.dll 
// as the command line argument, as shown below:
// LoadInvoke Myassembly.dll

using System;
using System.Reflection;
public class LoadInvoke
{
    public static void Main(string[] args)
    {
        Assembly a = Assembly.LoadFrom(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)
            {
                m.Invoke(obj, null);
            }
        }
    }
}

[C++] 
// LoadInvoke loads MyAssembly.dll and invokes the MyMethod1 method.
// After compiling this class, run LoadInvoke.exe with MyAssembly.dll
// as the command line argument, as shown below:
// LoadInvoke Myassembly.dll

#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

int main() {
   String* args[] = Environment::GetCommandLineArgs();
   Assembly*  a = Assembly::LoadFrom(args[1]);
   Type*  mytypes[] = a->GetTypes();
   BindingFlags flags = static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Public |
      BindingFlags::Static | BindingFlags::Instance | BindingFlags::DeclaredOnly);

   System::Collections::IEnumerator* myEnum = mytypes->GetEnumerator();
   while (myEnum->MoveNext()) {
      Type* t = __try_cast<Type*>(myEnum->Current);

      MethodInfo*  mi[] = t->GetMethods(flags);
      Object*  obj = Activator::CreateInstance(t);

      System::Collections::IEnumerator* myEnum = mi->GetEnumerator();
      while (myEnum->MoveNext()) {
         MethodInfo* m = __try_cast<MethodInfo*>(myEnum->Current);
         m->Invoke(obj, 0);
      }
   }
}

[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 obtain MyAssembly.dll.
using System;

public class MyAssembly
{
    public void MyMethod1()
    {
        Console.WriteLine("Invoking MyAssembly.MyMethod1");
    }    
}

[C++] 
// Use this class with the LoadInvoke program.
// Compile this class using csc /t:library MyAssembly.cs
// to obtain MyAssembly.dll.
#using <mscorlib.dll>
using namespace System;

public __gc class MyAssembly
{
public:
    void MyMethod1()
    {
        Console::WriteLine(S"Invoking MyAssembly.MyMethod1");
    }    
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Reflection

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: Mscorlib (Mscorlib.dll 内)

参照

Assembly メンバ | System.Reflection 名前空間