CodeCompileUnit クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
CodeDOM プログラム グラフのコンテナーを提供します。
public ref class CodeCompileUnit : System::CodeDom::CodeObject
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeCompileUnit : System.CodeDom.CodeObject
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeCompileUnit = class
inherit CodeObject
Public Class CodeCompileUnit
Inherits CodeObject
- 継承
- 派生
- 属性
例
次のコード例では、単純な "Hello World" プログラムのプログラム構造をモデル化するCodeCompileUnitを構築します。 このコード例は、このモデルからコードを生成する大規模な例の一部であり、 CodeDomProvider クラス用に提供されています。
// 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.
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
注釈
CodeCompileUnit は、CodeDOM プログラム グラフのコンテナーを提供します。
CodeCompileUnit には、CodeDOM ソース コード グラフを含む CodeNamespace オブジェクトと、プロジェクトによって参照されるアセンブリのコレクション、およびプロジェクト アセンブリの属性のコレクションを格納できるコレクションが含まれています。
CodeCompileUnitは、コンパイル単位に含まれるプログラム グラフに基づいてコードを生成する他のパラメーターと共に、ICodeGenerator実装のGenerateCodeFromCompileUnit メソッドに渡すことができます。
Note
一部の言語では、コンパイル ユニット内に 1 つのクラスを含む 1 つの名前空間のみがサポートされます。
コンストラクター
| 名前 | 説明 |
|---|---|
| CodeCompileUnit() |
CodeCompileUnit クラスの新しいインスタンスを初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| AssemblyCustomAttributes |
生成されたアセンブリのカスタム属性のコレクションを取得します。 |
| EndDirectives |
終了ディレクティブを含む CodeDirectiveCollection オブジェクトを取得します。 |
| Namespaces |
名前空間のコレクションを取得します。 |
| ReferencedAssemblies |
参照されるアセンブリを取得します。 |
| StartDirectives |
開始ディレクティブを含む CodeDirectiveCollection オブジェクトを取得します。 |
| UserData |
現在のオブジェクトのユーザー定義可能なデータを取得します。 (継承元 CodeObject) |
メソッド
| 名前 | 説明 |
|---|---|
| Equals(Object) |
指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |