CodeParameterDeclarationExpression CodeParameterDeclarationExpression CodeParameterDeclarationExpression CodeParameterDeclarationExpression Class

定義

表示方法、屬性或建構函式的參數宣告。Represents a parameter declaration for a method, property, or constructor.

public ref class CodeParameterDeclarationExpression : System::CodeDom::CodeExpression
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeParameterDeclarationExpression : System.CodeDom.CodeExpression
type CodeParameterDeclarationExpression = class
    inherit CodeExpression
Public Class CodeParameterDeclarationExpression
Inherits CodeExpression
繼承
CodeParameterDeclarationExpressionCodeParameterDeclarationExpressionCodeParameterDeclarationExpressionCodeParameterDeclarationExpression
屬性

範例

下列範例示範CodeParameterDeclarationExpression如何使用來宣告使用不同FieldDirection欄位參考型別規範之方法的參數。The following example demonstrates use of CodeParameterDeclarationExpression to declare parameters of a method using different FieldDirection field reference type specifiers.

// 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可以用來代表宣告方法、屬性或函式之參數的程式碼。CodeParameterDeclarationExpression can be used to represent code that declares a parameter for a method, property, or constructor.

Name屬性會指定參數的名稱。The Name property specifies the name of the parameter. Type屬性會指定參數的資料類型。The Type property specifies the data type of the parameter. Direction屬性會指定參數的方向修飾詞。The Direction property specifies the direction modifier of the parameter. CustomAttributes屬性會指定與參數相關聯的屬性。The CustomAttributes property specifies the attributes associated with the parameter.

建構函式

CodeParameterDeclarationExpression() CodeParameterDeclarationExpression() CodeParameterDeclarationExpression() CodeParameterDeclarationExpression()

初始化 CodeParameterDeclarationExpression 類別的新執行個體。Initializes a new instance of the CodeParameterDeclarationExpression class.

CodeParameterDeclarationExpression(CodeTypeReference, String) CodeParameterDeclarationExpression(CodeTypeReference, String) CodeParameterDeclarationExpression(CodeTypeReference, String) CodeParameterDeclarationExpression(CodeTypeReference, String)

使用指定的參數型別和名稱來初始化 CodeParameterDeclarationExpression 類別的新執行個體。Initializes a new instance of the CodeParameterDeclarationExpression class using the specified parameter type and name.

CodeParameterDeclarationExpression(String, String) CodeParameterDeclarationExpression(String, String) CodeParameterDeclarationExpression(String, String) CodeParameterDeclarationExpression(String, String)

使用指定的參數型別和名稱來初始化 CodeParameterDeclarationExpression 類別的新執行個體。Initializes a new instance of the CodeParameterDeclarationExpression class using the specified parameter type and name.

CodeParameterDeclarationExpression(Type, String) CodeParameterDeclarationExpression(Type, String) CodeParameterDeclarationExpression(Type, String) CodeParameterDeclarationExpression(Type, String)

使用指定的參數型別和名稱來初始化 CodeParameterDeclarationExpression 類別的新執行個體。Initializes a new instance of the CodeParameterDeclarationExpression class using the specified parameter type and name.

屬性

CustomAttributes CustomAttributes CustomAttributes CustomAttributes

取得或設定參數宣告的自訂屬性 (Attribute)。Gets or sets the custom attributes for the parameter declaration.

Direction Direction Direction Direction

取得或設定欄位的方向。Gets or sets the direction of the field.

Name Name Name Name

取得或設定參數的名稱。Gets or sets the name of the parameter.

Type Type Type Type

取得或設定參數的型別。Gets or sets the type of the parameter.

UserData UserData UserData UserData

取得目前物件的使用者可定義資料。Gets the user-definable data for the current object.

(Inherited from CodeObject)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

另請參閱