Caprices

CodeConstructor

メンバ

コンストラクタ

public CodeConstructor();
概要
System.CodeDom.CodeConstructor クラスの新しいインスタンスを初期化します。

生成したものをそのままメンバに追加するとprivateのコンストラクタになる


// クラス作成
CodeTypeDeclaration ctd = new CodeTypeDeclaration( "CodeConstructorSample" );

// コンストラクタ生成
CodeConstructor cc = new CodeConstructor();

// メンバ追加
ctd.Members.Add( cc );

// --------------------------------------------------

//    public class CodeConstructorSample
//    {
//        
//        private CodeConstructorSample()
//        {
//        }
//    }

▲ページ先頭へ

プロパティ

public CodeExpressionCollection BaseConstructorArgs{ get; }
CodeExpression
概要
基本コンストラクターの引数のコレクションを取得します。
戻り値
A System.CodeDom.CodeExpressionCollection 基本コンス トラクターの引数を格納しています。
public CodeExpressionCollection ChainedConstructorArgs{ get; }
CodeExpression
概要
チェイン コンストラクターの引数のコレクションを取得します。
戻り値
A System.CodeDom.CodeExpressionCollection チェイン コンス トラクター引数を格納しています。
Attributes
メンバーの属性を取得または設定します。 (Inherited from CodeTypeMember )
Comments
型メンバーのコメント コレクションを取得します。 (Inherited from CodeTypeMember )
CustomAttributes
メンバーのカスタム属性を取得または設定します。 (Inherited from CodeTypeMember )
EndDirectives
メンバーの終了ディレクティブを取得します。 (Inherited from CodeTypeMember )
ImplementationTypes
メソッドの実装が PrivateImplementationType プロパティで示されるプライベート メソッド実装である場合を除き、このメソッドによって実装されるインターフェイスのデータ型を取得します。 (Inherited from CodeMemberMethod )
LinePragma
型メンバーのステートメントが発生する行を取得または設定します。 (Inherited from CodeTypeMember )
Name
メンバーの名前を取得または設定します。 (Inherited from CodeTypeMember )
Parameters
メソッドのパラメーター宣言を取得します。 (Inherited from CodeMemberMethod )
PrivateImplementationType
このメソッドによってプライベート メソッドが実装されるインターフェイスがある場合に、そのインターフェイスのデータ型を取得または設定します。 (Inherited from CodeMemberMethod )
ReturnType
メソッドの戻り値のデータ型を取得または設定します。 (Inherited from CodeMemberMethod )
ReturnTypeCustomAttributes
メソッドの戻り値の型のカスタム属性を取得します。 (Inherited from CodeMemberMethod )
StartDirectives
メンバーの開始ディレクティブを取得します。 (Inherited from CodeTypeMember )
Statements
メソッド内で、ステートメントを取得します。 (Inherited from CodeMemberMethod )
TypeParameters
現在のジェネリック メソッドの型パラメーターを取得します。 (Inherited from CodeMemberMethod )
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)

▲ページ先頭へ

イベント

PopulateImplementationTypes
ImplementationTypes コレクションが最初にアクセスされたときに発生するイベント。 (Inherited from CodeMemberMethod )
PopulateParameters
Parameters コレクションが最初にアクセスされたときに発生するイベント。 (Inherited from CodeMemberMethod )
PopulateStatements
Statements コレクションが最初にアクセスされたときに発生するイベント。 (Inherited from CodeMemberMethod )

▲ページ先頭へ

この例では、CodeConstructorコンス トラクターのいくつかの型を宣言します。


// This example declares two types, one of which inherits from another, and creates a set of different styles of constructors using CodeConstructor.
// この例は、別のものから引き継ぐ1およびCodeConstructorを使って建設者の種々のスタイルのセットを作成するという2タイプを宣言する。

// Creates a new CodeCompileUnit to contain the program graph.
// プログラムグラフを含むように、新しいCodeCompileUnitを作成する。
CodeCompileUnit CompileUnit = new CodeCompileUnit();
// Declares a new namespace object and names it.
// 新しいnamespaceオブジェクトを宣言し、それを名付ける。
CodeNamespace Samples = new CodeNamespace("Samples");
// Adds the namespace object to the compile unit.
// namespaceオブジェクトを編集ユニットに追加する。
CompileUnit.Namespaces.Add( Samples );
// Adds a new namespace import for the System namespace.
// システムnamespaceのための新しいnamespace輸入を追加する。
Samples.Imports.Add( new CodeNamespaceImport("System") );

// Declares a new type and names it.
// 新しいタイプを宣言し、それを名付ける。
CodeTypeDeclaration BaseType = new CodeTypeDeclaration("BaseType");
// Adds the new type to the namespace object's type collection.
// 新しいタイプをnamespaceオブジェクトのタイプコレクションに追加する。
Samples.Types.Add(BaseType);

// Declares a default constructor that takes no arguments.
// 議論を全然取らないデフォルト建設者を宣言する。
CodeConstructor defaultConstructor = new CodeConstructor();
defaultConstructor.Attributes = MemberAttributes.Public;
// Adds the constructor to the Members collection of the BaseType.
// 建設者を、基づく型のメンバーコレクションに追加する。
BaseType.Members.Add(defaultConstructor);

// Declares a constructor that takes a string argument.
// ストリング議論を取る建設者を宣言する。
CodeConstructor stringConstructor = new CodeConstructor();
stringConstructor.Attributes = MemberAttributes.Public;
// Declares a parameter of type string named "TestStringParameter".
// 「TestStringParameter」と名付けられたタイプストリングのパラメータを宣言する。
stringConstructor.Parameters.Add( new CodeParameterDeclarationExpression("System.String", "TestStringParameter") );
// Adds the constructor to the Members collection of the BaseType.
// 建設者を、基づく型のメンバーコレクションに追加する。
BaseType.Members.Add(stringConstructor);

// Declares a type that derives from BaseType and names it.
// 基づく型から派生し、それを名付けるタイプを宣言する。
CodeTypeDeclaration DerivedType = new CodeTypeDeclaration("DerivedType");
// The DerivedType class inherits from the BaseType class.
// 派生型クラスは、基づく型クラスから引き継ぐ。
DerivedType.BaseTypes.Add( new CodeTypeReference("BaseType") );
// Adds the new type to the namespace object's type collection.
// 新しいタイプをnamespaceオブジェクトのタイプコレクションに追加する。
Samples.Types.Add(DerivedType);

// Declare a constructor that takes a string argument and calls the base class constructor with it.
// ストリング議論を取り、それによってベースクラス建設者を呼ぶ建設者を宣言しなさい。
CodeConstructor baseStringConstructor = new CodeConstructor();
baseStringConstructor.Attributes = MemberAttributes.Public;
// Declares a parameter of type string named "TestStringParameter".
// 「TestStringParameter」と名付けられたタイプストリングのパラメータを宣言する。
baseStringConstructor.Parameters.Add( new CodeParameterDeclarationExpression("System.String", "TestStringParameter") );
// Calls a base class constructor with the TestStringParameter parameter.
// TestStringParameterパラメータを持つ呼び出しベースクラス建設者。
baseStringConstructor.BaseConstructorArgs.Add( new CodeVariableReferenceExpression("TestStringParameter") );
// Adds the constructor to the Members collection of the DerivedType.
// 建設者を派生型のメンバーコレクションに追加する。
DerivedType.Members.Add(baseStringConstructor);

// Declares a constructor overload that calls another constructor for the type with a predefined argument.
// タイプのために、あらかじめ決められた議論によって別の建設者を呼ぶ建設者オーバーロードを宣言する。
CodeConstructor overloadConstructor = new CodeConstructor();
overloadConstructor.Attributes = MemberAttributes.Public;
// Sets the argument to pass to a base constructor method.
// 基本の建設者方法に移り変わるセット議論。
overloadConstructor.ChainedConstructorArgs.Add( new CodePrimitiveExpression("Test") );
// Adds the constructor to the Members collection of the DerivedType.
// 建設者を派生型のメンバーコレクションに追加する。
DerivedType.Members.Add(overloadConstructor);

// Declares a constructor overload that calls the default constructor for the type.
// タイプのためにデフォルト建設者を呼ぶ建設者オーバーロードを宣言する。
CodeConstructor overloadConstructor2 = new CodeConstructor();
overloadConstructor2.Attributes = MemberAttributes.Public;
overloadConstructor2.Parameters.Add( new CodeParameterDeclarationExpression("System.Int32", "TestIntParameter") );
// Sets the argument to pass to a base constructor method.
// 基本の建設者方法に移り変わるセット議論。
overloadConstructor2.ChainedConstructorArgs.Add( new CodeSnippetExpression("") );
// Adds the constructor to the Members collection of the DerivedType.
// 建設者を派生型のメンバーコレクションに追加する。
DerivedType.Members.Add(overloadConstructor2);

// A C# code generator produces the following source code for the preceeding example code:
// A C#コードジェネレータはpreceeding例コードのための以下のソースコードを作り出す:

// public class BaseType {
//
//     public BaseType() {
//     }
//
//     public BaseType(string TestStringParameter) {
//     }
// }
//
// public class DerivedType : BaseType {
//
//     public DerivedType(string TestStringParameter) :
//             base(TestStringParameter) {
//     }
//
//     public DerivedType() :
//             this("Test") {
//     }
//
//     public DerivedType(int TestIntParameter) :
//                this() {
//     }
// }

▲ページ先頭へ

定義


[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeConstructor : System.CodeDom.CodeMemberMethod

▲ページ先頭へ

クラス


#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.Runtime.InteropServices;

namespace System.CodeDom
{
	//
	// 概要:
	//     型のインスタンス コンス トラクターの宣言を表します。
	[ClassInterface( ClassInterfaceType.AutoDispatch )]
	[ComVisible( true )]
	public class CodeConstructor : CodeMemberMethod
	{
		//
		// 概要:
		//     System.CodeDom.CodeConstructor クラスの新しいインスタンスを初期化します。
		public CodeConstructor();

		//
		// 概要:
		//     基本コンス トラクターの引数のコレクションを取得します。
		//
		// 戻り値:
		//     A System.CodeDom.CodeExpressionCollection 基本コンス トラクターの引数を格納しています。
		public CodeExpressionCollection BaseConstructorArgs
		{
			get;
		}
		//
		// 概要:
		//     チェーンのコンス トラクターの引数のコレクションを取得します。
		//
		// 戻り値:
		//     A System.CodeDom.CodeExpressionCollection チェイン コンス トラクター引数を格納しています。
		public CodeExpressionCollection ChainedConstructorArgs
		{
			get;
		}
	}
}

▲ページ先頭へ