AssemblyBuilder クラスとは? わかりやすく解説

AssemblyBuilder クラス

動的アセンブリを定義および表現します

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

<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.None)> _
Public NotInheritable Class
 AssemblyBuilder
    Inherits Assembly
    Implements _AssemblyBuilder
Dim instance As AssemblyBuilder
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.None)] 
public sealed class AssemblyBuilder : Assembly,
 _AssemblyBuilder
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::None)] 
public ref class AssemblyBuilder sealed : public
 Assembly, _AssemblyBuilder
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.None) */ 
public final class AssemblyBuilder extends
 Assembly implements _AssemblyBuilder
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.None) 
public final class AssemblyBuilder extends
 Assembly implements _AssemblyBuilder
解説解説

動的アセンブリは、Reflection Emit API使用して作成されアセンブリです。Save メソッド使用して動的アセンブリ保存されるときに、動的モジュールアセンブリ保存されます。実行可能ファイル生成するには、SetEntryPoint メソッド呼び出してアセンブリへのエントリ ポイントであるメソッド識別する必要がありますアセンブリは、既定ではダイナミック リンク ライブラリ (DLL) として保存されますが、SetEntryPoint使用してコンソール アプリケーションまたは Windows ベースアプリケーション生成するように要求できます

動的アセンブリ複数動的モジュール含まれている場合、そのアセンブリマニフェスト ファイル名は、DefineDynamicModule の最初引数指定されているモジュール名に一致する必要があります

GetModules および GetLoadedModules などの基本クラス Assemblyメソッド中にはAssemblyBuilder オブジェクト呼び出されたときに正しく動作しないものがあります定義され動的アセンブリ読み込み読み込まれアセンブリに対してメソッド呼び出します。たとえば、返されモジュール リストリソース モジュール含まれているようにするには、読み込まれAssembly オブジェクトに対して GetModules呼び出します。

KeyPair使用した動的アセンブリへの署名は、アセンブリディスク保存されるまで有効ではありません。したがって遷移動的アセンブリでは厳密な名前機能しません。

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Reflection.Assembly
    System.Reflection.Emit.AssemblyBuilder
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AssemblyBuilder メンバ
System.Reflection.Emit 名前空間

AssemblyBuilder クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

ASP.NET プロジェクト内の 1 つ上の仮想パスからアセンブリビルドするためのコンテナ提供します

名前空間: System.Web.Compilation
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class AssemblyBuilder
Dim instance As AssemblyBuilder
public class AssemblyBuilder
public ref class AssemblyBuilder
public class AssemblyBuilder
public class AssemblyBuilder
解説解説

1 つ上のファイルコンパイル済みアセンブリビルドするには、AssemblyBuilder クラスインスタンスが BuildProvider クラスメソッドと共に使用されます。

BuildProvider クラスビルド機能ファイル別に定義しますAssemblyBuilder クラスは、各 BuildProvider インスタンスによって指定されソース コード1 つアセンブリ結合しますASP.NET ビルド環境では、1 つ上のファイルか1 つアセンブリ構築するときに、AssemblyBuilder オブジェクトBuildProvider メソッド渡されます。これにより、各 BuildProvider インスタンスは、アセンブリ全体に対してそれぞれのファイルソース コード指定できます

ASP.NET ビルド環境では、プロジェクト内のファイルが必要とする言語コンパイラは、BuildProvider.CodeCompilerType プロパティ基づいて判断されます。ASP.NET ビルド環境では、コンパイラ設定基づいてファイルグループ化し、同一コンパイラを必要とするファイルかアセンブリビルドます。

CodeDomProvider プロパティは、ASP.NET ビルド環境が各 BuildProvider 実装指定されるソース コードアセンブリコンパイルするのに使用する CodeDomProvider 実装示します

BuildProvider オブジェクトは、AddCodeCompileUnit メソッド使用して、CodeDOM グラフ形式ソース コード指定しますBuildProvider オブジェクトは、CreateCodeFile メソッド使用して物理ファイル内に格納されソース コード指定します

BuildProvider オブジェクト適切な AssemblyBuilder メソッド使用してソース コード指定した後は、ASP.NET ビルド環境は、AssemblyBuilder クラス使用して収集済みソース コードアセンブリコンパイルます。

使用例使用例

簡単なビルド プロバイダを、抽象基本クラス BuildProvider から継承して実装するコード例次に示しますビルド プロバイダは、基本クラスメンバである CodeCompilerType、GetGeneratedType、および GenerateCode をオーバーライドます。

GenerateCode メソッド実装では、ビルド プロバイダCreateCodeFile メソッド使用してアセンブリ コンパイル用の生成済みコード追加します

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.IO
Imports System.Text
Imports System.Web
Imports System.Web.Compilation
Imports System.CodeDom.Compiler
Imports System.CodeDom
Imports System.Security
Imports System.Security.Permissions

<PermissionSet(SecurityAction.Demand, Unrestricted := true)>
 _
Public Class SampleBuildProvider
    Inherits BuildProvider

    Protected _compilerType As CompilerType
 = Nothing

    Public Sub New()
        _compilerType = GetDefaultCompilerType()
    End Sub

    ' Return the internal CompilerType member 
    ' defined in this implementation.
    Public Overrides ReadOnly
 Property CodeCompilerType() As CompilerType
        Get
            CodeCompilerType = _compilerType
        End Get
    End Property

    ' Define a method that returns details for the 
    ' code compiler for this build provider.
    Public Function GetCompilerTypeDetails()
 As String
        Dim details As StringBuilder = New
 StringBuilder("")

        If Not _compilerType Is
 Nothing Then
            ' Format a string that contains the code compiler
            ' implementation, and various compiler details.

            details.AppendFormat("CodeDomProvider type: {0}; ",
 _
                _compilerType.CodeDomProviderType.ToString())
            details.AppendFormat("Compiler debug build = {0};
 ", _
                _compilerType.CompilerParameters.IncludeDebugInformation.ToString())
            details.AppendFormat("Compiler warning level = {0};
 ", _
                _compilerType.CompilerParameters.WarningLevel.ToString())

            If Not _compilerType.CompilerParameters.CompilerOptions
 Is Nothing Then
                details.AppendFormat("Compiler options: {0}; ",
 _
                    _compilerType.CompilerParameters.CompilerOptions.ToString())
            End If
        End If
        Return details.ToString()
    End Function

    ' Define the build provider implementation of the GenerateCode method.
    Public Overrides Sub
 GenerateCode(ByVal assemBuilder As AssemblyBuilder)
        ' Generate a code compile unit, and add it to
        ' the assembly builder.

        Dim tw As TextWriter = assemBuilder.CreateCodeFile(Me)
        If Not tw Is Nothing
 Then
            Try
                ' Generate the code compile unit from the virtual path.
                Dim compileUnit As CodeCompileUnit
 = _
                        SampleClassGenerator.BuildCompileUnitFromPath(VirtualPath)

                ' Generate the source for the code compile unit, 
                ' and write it to a file specified by the assembly builder.
                Dim provider As CodeDomProvider
 = assemBuilder.CodeDomProvider
                provider.CreateGenerator().GenerateCodeFromCompileUnit(compileUnit,
 tw, Nothing)
            Finally
                tw.Close()
            End Try

        End If
    End Sub

    Public Overrides Function
 GetGeneratedType(ByVal results As CompilerResults)
 As System.Type
        Dim typeName As String
 = SampleClassGenerator.TypeName

        Return results.CompiledAssembly.GetType(typeName)
    End Function

End Class
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Compilation;
using System.CodeDom.Compiler;
using System.CodeDom;
using System.Security;
using System.Security.Permissions;

// Define a simple build provider implementation.
[PermissionSet(SecurityAction.Demand, Unrestricted = true)]
public class SampleBuildProvider : BuildProvider
{
    // Define an internal member for the compiler type.
    protected CompilerType _compilerType = null;

    public SampleBuildProvider()
    {
        // Set the compiler to use Visual Basic.
        _compilerType = GetDefaultCompilerTypeForLanguage("C#");
    }

    // Return the internal CompilerType member 
    // defined in this implementation.
    public override CompilerType CodeCompilerType
    {
        get { return _compilerType; }
    }

    // Define a method that returns details for the 
    // code compiler for this build provider.
    public string GetCompilerTypeDetails()
    {
        StringBuilder details = new StringBuilder("");

        if (_compilerType != null)
        {
            // Format a string that contains the code compiler
            // implementation, and various compiler details.

            details.AppendFormat("CodeDomProvider type: {0}; \n",
                _compilerType.CodeDomProviderType.ToString());
            details.AppendFormat("Compiler debug build = {0}; \n",
                _compilerType.CompilerParameters.IncludeDebugInformation.ToString());
            details.AppendFormat("Compiler warning level = {0}; \n",
                _compilerType.CompilerParameters.WarningLevel.ToString());

            if (_compilerType.CompilerParameters.CompilerOptions
 != null)
            {
                details.AppendFormat("Compiler options: {0}; \n",
                    _compilerType.CompilerParameters.CompilerOptions.ToString());
            }
        }
        return details.ToString();
    }


    // Define the build provider implementation of the GenerateCode
 method.
    public override void GenerateCode(AssemblyBuilder
 assemBuilder)
    {
        // Generate a code compile unit, and add it to
        // the assembly builder.

        TextWriter tw = assemBuilder.CreateCodeFile(this);
        if (tw != null)
        {
            try
            {
                // Generate the code compile unit from the virtual path.
                CodeCompileUnit compileUnit = SampleClassGenerator.BuildCompileUnitFromPath(VirtualPath);

                // Generate the source for the code compile unit, 
                // and write it to a file specified by the assembly
 builder.
                CodeDomProvider provider = assemBuilder.CodeDomProvider;
                provider.CreateGenerator().GenerateCodeFromCompileUnit(compileUnit,
 tw, null);
            }
            finally
            {
                tw.Close();
            }
        }
    }

    public override System.Type GetGeneratedType(CompilerResults
 results)
    {
        string typeName = SampleClassGenerator.TypeName;

        return results.CompiledAssembly.GetType(typeName);
    }
}
継承階層継承階層
System.Object
  System.Web.Compilation.AssemblyBuilder
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AssemblyBuilder メンバ
System.Web.Compilation 名前空間
BuildProvider
BuildManager
ClientBuildManager



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「AssemblyBuilder クラス」の関連用語

AssemblyBuilder クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



AssemblyBuilder クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS