閱讀英文版本

分享方式:


CodeParameterDeclarationExpression 類別

定義

表示方法、屬性或建構函式的參數宣告。

C#
public class CodeParameterDeclarationExpression : System.CodeDom.CodeExpression
C#
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeParameterDeclarationExpression : System.CodeDom.CodeExpression
繼承
CodeParameterDeclarationExpression
屬性

範例

下列範例示範如何使用 CodeParameterDeclarationExpression 不同的 FieldDirection 字段參考型別規範來宣告方法的參數。

C#
// Declares a method.
CodeMemberMethod method1 = new CodeMemberMethod();
method1.Name = "TestMethod";

// Declares a string parameter passed by reference.
CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression("System.String", "stringParam");
param1.Direction = FieldDirection.Ref;
method1.Parameters.Add(param1);

// Declares a Int32 parameter passed by incoming field.
CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression("System.Int32", "intParam");
param2.Direction = FieldDirection.Out;
method1.Parameters.Add(param2);

// A C# code generator produces the following source code for the preceeding example code:

//        private void TestMethod(ref string stringParam, out int intParam) {
//        }

備註

CodeParameterDeclarationExpression 可用來表示宣告方法、屬性或建構函式之參數的程序代碼。

屬性 Name 會指定參數的名稱。 屬性 Type 會指定 參數的數據類型。 屬性 Direction 會指定 參數的方向修飾詞。 屬性 CustomAttributes 會指定與 參數相關聯的屬性。

建構函式

CodeParameterDeclarationExpression()

初始化 CodeParameterDeclarationExpression 類別的新執行個體。

CodeParameterDeclarationExpression(CodeTypeReference, String)

使用指定的參數型別和名稱來初始化 CodeParameterDeclarationExpression 類別的新執行個體。

CodeParameterDeclarationExpression(String, String)

使用指定的參數型別和名稱來初始化 CodeParameterDeclarationExpression 類別的新執行個體。

CodeParameterDeclarationExpression(Type, String)

使用指定的參數型別和名稱來初始化 CodeParameterDeclarationExpression 類別的新執行個體。

屬性

CustomAttributes

取得或設定參數宣告的自訂屬性 (Attribute)。

Direction

取得或設定欄位的方向。

Name

取得或設定參數的名稱。

Type

取得或設定參數的類型。

UserData

取得目前物件的使用者可定義資料。

(繼承來源 CodeObject)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱