CodeCompileUnitとは? わかりやすく解説

CodeCompileUnit クラス

CodeDOM プログラム グラフ用のコンテナ提供します

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

<SerializableAttribute> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class CodeCompileUnit
    Inherits CodeObject
Dim instance As CodeCompileUnit
[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class CodeCompileUnit : CodeObject
[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class CodeCompileUnit : public
 CodeObject
/** @attribute SerializableAttribute() */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class CodeCompileUnit extends CodeObject
SerializableAttribute 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class CodeCompileUnit extends
 CodeObject
解説解説
使用例使用例

簡単な "Hello World" プログラム構造モデル化した CodeCompileUnit構築するコード例次に示します。このコード例は、このモデルからコード作成するコード例一部分であり、CodeDomProvider クラス向けに提供されています。

' Build a Hello World program graph using 
' System.CodeDom types.
Public Shared Function BuildHelloWorldGraph()
 As CodeCompileUnit

    ' Create a new CodeCompileUnit to contain 
    ' the program graph.
    Dim compileUnit As New
 CodeCompileUnit()

    ' Declare a new namespace called Samples.
    Dim samples As New CodeNamespace("Samples")

    ' Add the new namespace to the compile unit.
    compileUnit.Namespaces.Add(samples)

    ' Add the new namespace import for the System namespace.
    samples.Imports.Add(New CodeNamespaceImport("System"))

    ' Declare a new type called Class1.
    Dim class1 As New CodeTypeDeclaration("Class1")

    ' Add the new type to the namespace type collection.
    samples.Types.Add(class1)

    ' Declare a new code entry point method.
    Dim start As New CodeEntryPointMethod()

    ' Create a type reference for the System.Console class.
    Dim csSystemConsoleType As New
 CodeTypeReferenceExpression( _
        "System.Console")

    ' Build a Console.WriteLine statement.
    Dim cs1 As New CodeMethodInvokeExpression(
 _
        csSystemConsoleType, "WriteLine", _
        New CodePrimitiveExpression("Hello
 World!"))

    ' Add the WriteLine call to the statement collection.
    start.Statements.Add(cs1)

    ' Build another Console.WriteLine statement.
    Dim cs2 As New CodeMethodInvokeExpression(
 _
        csSystemConsoleType, "WriteLine", _
        New CodePrimitiveExpression("Press
 the Enter key to continue."))

    ' Add the WriteLine call to the statement collection.
    start.Statements.Add(cs2)

    ' Build a call to System.Console.ReadLine.
    Dim csReadLine As New
 CodeMethodInvokeExpression( _
        csSystemConsoleType, "ReadLine")

    ' Add the ReadLine statement.
    start.Statements.Add(csReadLine)

    ' Add the code entry point method to
    ' the Members collection of the type.
    class1.Members.Add(start)

    Return compileUnit
End Function
// Build a Hello World program graph using 
// System.CodeDom types.
public static CodeCompileUnit BuildHelloWorldGraph()
{
    // Create a new CodeCompileUnit to contain 
    // the program graph.
    CodeCompileUnit compileUnit = new CodeCompileUnit();

    // Declare a new namespace called Samples.
    CodeNamespace samples = new CodeNamespace("Samples");
    // Add the new namespace to the compile unit.
    compileUnit.Namespaces.Add(samples);

    // Add the new namespace import for the System namespace.
    samples.Imports.Add(new CodeNamespaceImport("System"));

    // Declare a new type called Class1.
    CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1");
    // Add the new type to the namespace type collection.
    samples.Types.Add(class1);

    // Declare a new code entry point method.
    CodeEntryPointMethod start = new CodeEntryPointMethod();

    // Create a type reference for the System.Console class.
    CodeTypeReferenceExpression csSystemConsoleType = new CodeTypeReferenceExpression("System.Console");

    // Build a Console.WriteLine statement.
    CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression(
        csSystemConsoleType, "WriteLine",
        new CodePrimitiveExpression("Hello World!"));

    // Add the WriteLine call to the statement collection.
    start.Statements.Add(cs1);

    // Build another Console.WriteLine statement.
    CodeMethodInvokeExpression cs2 = new CodeMethodInvokeExpression(
        csSystemConsoleType, "WriteLine",
        new CodePrimitiveExpression("Press the Enter key
 to continue."));

    // Add the WriteLine call to the statement collection.
    start.Statements.Add(cs2);

    // Build a call to System.Console.ReadLine.
    CodeMethodInvokeExpression csReadLine = new CodeMethodInvokeExpression(
        csSystemConsoleType, "ReadLine");

    // Add the ReadLine statement.
    start.Statements.Add(csReadLine);

    // Add the code entry point method to
    // the Members collection of the type.
    class1.Members.Add(start);

    return compileUnit;
}
// Build a Hello World program graph using 
// System::CodeDom types.
static CodeCompileUnit^ BuildHelloWorldGraph()
{
    // Create a new CodeCompileUnit to contain 
    // the program graph.
    CodeCompileUnit^ compileUnit = gcnew CodeCompileUnit;

    // Declare a new namespace called Samples.
    CodeNamespace^ samples = gcnew CodeNamespace( "Samples" );

    // Add the new namespace to the compile unit.
    compileUnit->Namespaces->Add( samples );

    // Add the new namespace import for the System namespace.
    samples->Imports->Add( gcnew CodeNamespaceImport( "System" )
 );

    // Declare a new type called Class1.
    CodeTypeDeclaration^ class1 = gcnew CodeTypeDeclaration( "Class1" );

    // Add the new type to the namespace's type collection.
    samples->Types->Add( class1 );

    // Declare a new code entry point method.
    CodeEntryPointMethod^ start = gcnew CodeEntryPointMethod;

    // Create a type reference for the System::Console class.
    CodeTypeReferenceExpression^ csSystemConsoleType = gcnew CodeTypeReferenceExpression(
 "System.Console" );

    // Build a Console::WriteLine statement.
    CodeMethodInvokeExpression^ cs1 = gcnew CodeMethodInvokeExpression( csSystemConsoleType,"WriteLine",
 gcnew CodePrimitiveExpression("Hello World!") );

    // Add the WriteLine call to the statement collection.
    start->Statements->Add( cs1 );

    // Build another Console::WriteLine statement.
    CodeMethodInvokeExpression^ cs2 = gcnew CodeMethodInvokeExpression( csSystemConsoleType,"WriteLine",
 gcnew CodePrimitiveExpression( "Press the Enter key to continue." ) );

    // Add the WriteLine call to the statement collection.
    start->Statements->Add( cs2 );

    // Build a call to System::Console::ReadLine.
    CodeMethodReferenceExpression^ csReadLine = gcnew CodeMethodReferenceExpression(
 csSystemConsoleType, "ReadLine" );
    CodeMethodInvokeExpression^ cs3 = gcnew CodeMethodInvokeExpression( csReadLine,
 gcnew array<CodeExpression^>(0) );

    // Add the ReadLine statement.
    start->Statements->Add( cs3 );

    // Add the code entry point method to
    // the Members collection of the type.
    class1->Members->Add( start );
    return compileUnit;
}
継承階層継承階層
System.Object
   System.CodeDom.CodeObject
    System.CodeDom.CodeCompileUnit
       System.CodeDom.CodeSnippetCompileUnit
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

CodeCompileUnit コンストラクタ


CodeCompileUnit プロパティ


CodeCompileUnit メソッド


CodeCompileUnit メンバ

CodeDOM プログラム グラフ用のコンテナ提供します

CodeCompileUnit データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド CodeCompileUnit CodeCompileUnit クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ AssemblyCustomAttributes 生成されるアセンブリカスタム属性コレクション取得します
パブリック プロパティ EndDirectives 終了ディレクティブを含む CodeDirectiveCollection オブジェクト取得します
パブリック プロパティ Namespaces 名前空間コレクション取得します
パブリック プロパティ ReferencedAssemblies 参照されアセンブリ取得します
パブリック プロパティ StartDirectives 開始ディレクティブを含む CodeDirectiveCollection オブジェクト取得します
パブリック プロパティ UserData  現在のオブジェクトユーザー定義可能なデータ取得または設定します。(CodeObject から継承されます。)
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

CodeCompileUnit クラス
System.CodeDom 名前空間



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

辞書ショートカット

すべての辞書の索引

「CodeCompileUnit」の関連用語

CodeCompileUnitのお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS