CodeParameterDeclarationExpression 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示方法、屬性或建構函式的參數宣告。
public ref class CodeParameterDeclarationExpression : System::CodeDom::CodeExpression
public class CodeParameterDeclarationExpression : System.CodeDom.CodeExpression
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeParameterDeclarationExpression : System.CodeDom.CodeExpression
type CodeParameterDeclarationExpression = class
inherit CodeExpression
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeParameterDeclarationExpression = class
inherit CodeExpression
Public Class CodeParameterDeclarationExpression
Inherits CodeExpression
- 繼承
- 屬性
下列範例示範如何使用 CodeParameterDeclarationExpression 不同的 FieldDirection 字段參考型別規範來宣告方法的參數。
// Declares a method.
CodeMemberMethod^ method1 = gcnew CodeMemberMethod;
method1->Name = "TestMethod";
// Declares a string parameter passed by reference.
CodeParameterDeclarationExpression^ param1 = gcnew CodeParameterDeclarationExpression( "System.String","stringParam" );
param1->Direction = FieldDirection::Ref;
method1->Parameters->Add( param1 );
// Declares a Int32 parameter passed by incoming field.
CodeParameterDeclarationExpression^ param2 = gcnew 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) {
// }
// 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) {
// }
' Declares a method.
Dim method1 As New CodeMemberMethod()
method1.Name = "TestMethod"
' Declares a string parameter passed by reference.
Dim param1 As New CodeParameterDeclarationExpression("System.String", "stringParam")
param1.Direction = FieldDirection.Ref
method1.Parameters.Add(param1)
' Declares a Int32 parameter passed by incoming field.
Dim param2 As New CodeParameterDeclarationExpression("System.Int32", "intParam")
param2.Direction = FieldDirection.Out
method1.Parameters.Add(param2)
' A Visual Basic code generator produces the following source code for the preceeding example code:
' Private Sub TestMethod(ByRef stringParam As String, ByRef intParam As Integer)
' End Sub
CodeParameterDeclarationExpression 可用來表示宣告方法、屬性或建構函式之參數的程序代碼。
屬性 Name 會指定參數的名稱。 屬性 Type 會指定 參數的數據類型。 屬性 Direction 會指定 參數的方向修飾詞。 屬性 CustomAttributes 會指定與 參數相關聯的屬性。
Code |
初始化 CodeParameterDeclarationExpression 類別的新執行個體。 |
Code |
使用指定的參數型別和名稱來初始化 CodeParameterDeclarationExpression 類別的新執行個體。 |
Code |
使用指定的參數型別和名稱來初始化 CodeParameterDeclarationExpression 類別的新執行個體。 |
Code |
使用指定的參數型別和名稱來初始化 CodeParameterDeclarationExpression 類別的新執行個體。 |
Custom |
取得或設定參數宣告的自訂屬性 (Attribute)。 |
Direction |
取得或設定欄位的方向。 |
Name |
取得或設定參數的名稱。 |
Type |
取得或設定參數的類型。 |
User |
取得目前物件的使用者可定義資料。 (繼承來源 CodeObject) |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
Get |
做為預設雜湊函式。 (繼承來源 Object) |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
傳回代表目前物件的字串。 (繼承來源 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 |