CodeCompileUnit クラス
アセンブリ: System (system.dll 内)

<SerializableAttribute> _ <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ <ComVisibleAttribute(True)> _ Public Class CodeCompileUnit Inherits CodeObject
[SerializableAttribute] [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] [ComVisibleAttribute(true)] public class CodeCompileUnit : CodeObject
[SerializableAttribute] [ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] [ComVisibleAttribute(true)] public ref class CodeCompileUnit : public CodeObject

CodeCompileUnit は、CodeDOM プログラム グラフ用のコンテナを提供します。
CodeCompileUnit には、CodeDOM ソース コード グラフを含んだ CodeNamespace オブジェクトを格納できるコレクション、プロジェクトで参照されるアセンブリのコレクション、およびプロジェクト アセンブリの属性のコレクションが含まれています。
CodeCompileUnit は、他のパラメータと共に ICodeGenerator の実装の GenerateCodeFromCompileUnit メソッドに渡すことで、そのコンパイル単位に含まれるプログラム グラフに基づくコードを生成できます。
![]() |
---|

簡単な "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.CodeDom.CodeObject
System.CodeDom.CodeCompileUnit
System.CodeDom.CodeSnippetCompileUnit


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CodeCompileUnit コンストラクタ
アセンブリ: System (system.dll 内)


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


CodeCompileUnit プロパティ

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

CodeCompileUnit メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

CodeCompileUnit メンバ
CodeDOM プログラム グラフ用のコンテナを提供します。
CodeCompileUnit データ型で公開されるメンバを以下の表に示します。


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

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

Weblioに収録されているすべての辞書からCodeCompileUnitを検索する場合は、下記のリンクをクリックしてください。

- CodeCompileUnitのページへのリンク