CodeCompileUnit
メンバ
プロパティ
-
public
CodeNamespaceCollection
Namespaces{ get; }
【 CodeNamespace 】 -
- 概要
- 名前空間のコレクションを取得します。
- 戻り値
- A System.CodeDom.CodeNamespaceCollection コンパイル単位を使用する名前空間を示します。
- public StringCollection ReferencedAssemblies{ get; }
-
- 概要
- 参照アセンブリを取得します。
- 戻り値
- A System.Collections.Specialized.StringCollection 、参照アセンブリのファイル名を格納しています。
-
public
CodeAttributeDeclarationCollection
AssemblyCustomAttributes{ get; }
【 CodeAttributeDeclaration 】 -
- 概要
- 生成されたアセンブリのカスタム属性のコレクションを取得します。
- 戻り値
- A System.CodeDom.CodeAttributeDeclarationCollection 生成されたアセンブリのカスタム属性を示します。
-
public
CodeDirectiveCollection
StartDirectives{ get; }
【 CodeDirective 】 -
- 概要
- 開始ディレクティブを含む CodeDirectiveCollection オブジェクトを取得します。
- 戻り値
- A System.CodeDom.CodeDirectiveCollection オブジェクトを含むディレクティブを開始します。
-
public
CodeDirectiveCollection
EndDirectives{ get; }
【 CodeDirective 】 -
- 概要
- 終了ディレクティブを含む CodeDirectiveCollection オブジェクトを取得します。
- 戻り値
- A System.CodeDom.CodeDirectiveCollection 終了ディレクティブを含むオブジェクト。
- UserData
- 現在のオブジェクトのユーザー定義可能なデータを取得します。 (Inherited from CodeObject )
メソッド
- Equals(Object)
- 指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。 (Inherited from Object)
- GetHashCode()
- 既定のハッシュ関数として機能します。 (Inherited from Object)
- GetType()
- 現在のインスタンスの Type を取得します。 (Inherited from Object)
- MemberwiseClone()
- 現在の Object の簡易コピーを作成します。 (Inherited from Object)
- ToString()
- 現在のオブジェクトを表す文字列を返します。 (Inherited from Object)
例
次のコード例の構成要素をCodeCompileUnit単純な"Hello World"プログラムのプログラムの構造をモデル化します。 このコード例も、このモデルからコードを生成し、ために用意されている長い例の一部は、CodeDomProviderクラス。
// Build a Hello World program graph using System.CodeDom types.
// System.CodeDomを使ってあいさつ世界プログラムグラフを築きなさい タイプする 。
public static CodeCompileUnit BuildHelloWorldGraph()
{
// Create a new CodeCompileUnit to contain the program graph.
// プログラムグラフを含むように、新しいCodeCompileUnitを作成しなさい。
CodeCompileUnit compileUnit = new CodeCompileUnit();
// Declare a new namespace called Samples.
// サンプルと呼ばれる新しいnamespaceを宣言しなさい。
CodeNamespace samples = new CodeNamespace( "Samples" );
// Add the new namespace to the compile unit.
// 新しいnamespaceを編集ユニットに追加しなさい。
compileUnit.Namespaces.Add( samples );
// Add the new namespace import for the System namespace.
// システムnamespaceのための新しいnamespace輸入を追加しなさい。
samples.Imports.Add( new CodeNamespaceImport( "System" ) );
// Declare a new type called Class1.
// Class1と呼ばれる新しいタイプを宣言しなさい。
CodeTypeDeclaration class1 = new CodeTypeDeclaration( "Class1" );
// Add the new type to the namespace type collection.
// 新しいタイプをnamespaceタイプコレクションに追加しなさい。
samples.Types.Add( class1 );
// Declare a new code entry point method.
// 新しいコードエントリポイント方法を宣言しなさい。
CodeEntryPointMethod start = new CodeEntryPointMethod();
// Create a type reference for the System.Console class.
// System.Consoleクラスのためのタイプ参照を作成しなさい。
CodeTypeReferenceExpression csSystemConsoleType =
new CodeTypeReferenceExpression(
"System.Console"
);
// Build a Console.WriteLine statement.
// Console.WriteLineステートメントを築きなさい。
CodeMethodInvokeExpression cs1 =
new CodeMethodInvokeExpression(
csSystemConsoleType,
"WriteLine",
new CodePrimitiveExpression( "Hello World!" )
);
// Add the WriteLine call to the statement collection.
// WriteLine呼び出しをステートメントコレクションに追加しなさい。
start.Statements.Add( cs1 );
// Build another Console.WriteLine statement.
// 別のConsole.WriteLineステートメントを築きなさい。
CodeMethodInvokeExpression cs2 =
new CodeMethodInvokeExpression(
csSystemConsoleType,
"WriteLine",
new CodePrimitiveExpression( "Press the Enter key to continue." )
);
// Add the WriteLine call to the statement collection.
// WriteLine呼び出しをステートメントコレクションに追加しなさい。
start.Statements.Add( cs2 );
// Build a call to System.Console.ReadLine.
// 呼び出しをSystem.Console.ReadLineに築きなさい。
CodeMethodInvokeExpression csReadLine =
new CodeMethodInvokeExpression(
csSystemConsoleType,
"ReadLine"
);
// Add the ReadLine statement.
// ReadLineステートメントを追加しなさい。
start.Statements.Add( csReadLine );
// Add the code entry point method to the Members collection of the type.
// コードエントリポイント方法をタイプのメンバーコレクションに追加しなさい。
class1.Members.Add( start );
return compileUnit;
}
定義
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeCompileUnit : System.CodeDom.CodeObject
クラス
#region アセンブリ System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// C:¥Program Files (x86)¥Reference Assemblies¥Microsoft¥Framework¥.NETFramework¥v4.6.1¥System.dll
#endregion
using System.Collections.Specialized;
using System.Runtime.InteropServices;
namespace System.CodeDom
{
//
// 概要:
// CodeDOM プログラム グラフ用のコンテナーを提供します。
[ClassInterface( ClassInterfaceType.AutoDispatch )]
[ComVisible( true )]
public class CodeCompileUnit : CodeObject
{
//
// 概要:
// System.CodeDom.CodeCompileUnit クラスの新しいインスタンスを初期化します。
public CodeCompileUnit();
//
// 概要:
// 名前空間のコレクションを取得します。
//
// 戻り値:
// A System.CodeDom.CodeNamespaceCollection コンパイル単位を使用する名前空間を示します。
public CodeNamespaceCollection Namespaces
{
get;
}
//
// 概要:
// 参照アセンブリを取得します。
//
// 戻り値:
// A System.Collections.Specialized.StringCollection 、参照アセンブリのファイル名を格納しています。
public StringCollection ReferencedAssemblies
{
get;
}
//
// 概要:
// 生成されたアセンブリのカスタム属性のコレクションを取得します。
//
// 戻り値:
// A System.CodeDom.CodeAttributeDeclarationCollection 生成されたアセンブリのカスタム属性を示します。
public CodeAttributeDeclarationCollection AssemblyCustomAttributes
{
get;
}
//
// 概要:
// 取得、 System.CodeDom.CodeDirectiveCollection オブジェクトを含むディレクティブを開始します。
//
// 戻り値:
// A System.CodeDom.CodeDirectiveCollection オブジェクトを含むディレクティブを開始します。
public CodeDirectiveCollection StartDirectives
{
get;
}
//
// 概要:
// 取得、 System.CodeDom.CodeDirectiveCollection 終了ディレクティブを含むオブジェクト。
//
// 戻り値:
// A System.CodeDom.CodeDirectiveCollection 終了ディレクティブを含むオブジェクト。
public CodeDirectiveCollection EndDirectives
{
get;
}
}
}