CodeArgumentReferenceExpression CodeArgumentReferenceExpression CodeArgumentReferenceExpression CodeArgumentReferenceExpression Class

定義

代表傳遞至方法之引數值的參考。Represents a reference to the value of an argument passed to a method.

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

範例

下列範例程式碼會定義方法, Console.WriteLine以叫用以輸出傳遞給方法的字串參數。The following example code defines a method that invokes Console.WriteLine to output the string parameter passed to the method. CodeArgumentReferenceExpression參考透過方法參數名稱傳遞至方法的引數。A CodeArgumentReferenceExpression references the argument passed to the method by method parameter name.

// Declare a method that accepts a string parameter named text.
CodeMemberMethod^ cmm = gcnew CodeMemberMethod;
cmm->Parameters->Add( gcnew CodeParameterDeclarationExpression( "String","text" ) );
cmm->Name = "WriteString";
cmm->ReturnType = gcnew CodeTypeReference( "System::Void" );
array<CodeExpression^>^ce = {gcnew CodeArgumentReferenceExpression( "test1" )};

// Create a method invoke statement to output the string passed to the method.
CodeMethodInvokeExpression^ cmie = gcnew CodeMethodInvokeExpression( gcnew CodeTypeReferenceExpression( "Console" ),"WriteLine",ce );

// Add the method invoke expression to the method's statements collection.
cmm->Statements->Add( cmie );

// A C++ code generator produces the following source code for the preceeding example code:
// private:
//  void WriteString(String text) {
//       Console::WriteLine(text);
// }
           // Declare a method that accepts a string parameter named text.
           CodeMemberMethod cmm = new CodeMemberMethod();
           cmm.Parameters.Add( new CodeParameterDeclarationExpression("String", "text") );
           cmm.Name = "WriteString";
           cmm.ReturnType = new CodeTypeReference("System.Void");        
                   
           // Create a method invoke statement to output the string passed to the method.
           CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("Console"), "WriteLine", new CodeArgumentReferenceExpression("text") );

           // Add the method invoke expression to the method's statements collection.
           cmm.Statements.Add( cmie );

           // A C# code generator produces the following source code for the preceeding example code:        
           //        private void WriteString(String text) 
           //        {
           //            Console.WriteLine(text);
           //        }                         
 ' Declare a method that accepts a string parameter named text.
 Dim cmm As New CodeMemberMethod()
 cmm.Parameters.Add(New CodeParameterDeclarationExpression("String", "text"))
 cmm.Name = "WriteString"
 cmm.ReturnType = New CodeTypeReference("System.Void")
 
 ' Create a method invoke statement to output the string passed to the method.
 Dim cmie As New CodeMethodInvokeExpression(New CodeTypeReferenceExpression("Console"), "WriteLine", New CodeArgumentReferenceExpression("text"))
 
 ' Add the method invoke expression to the method's statements collection.
 cmm.Statements.Add(cmie)

 ' A Visual Basic code generator produces the following source code for the preceeding example code:
 '		Private Sub WriteString(ByVal [text] As [String])
 '			Console.WriteLine([text])
 '		End Sub

備註

CodeArgumentReferenceExpression可以在方法中用來參考已傳遞至方法之參數的值。CodeArgumentReferenceExpression can be used in a method to reference the value of a parameter that has been passed to the method.

ParameterName屬性會指定要參考之參數的名稱。The ParameterName property specifies the name of the parameter to reference.

建構函式

CodeArgumentReferenceExpression() CodeArgumentReferenceExpression() CodeArgumentReferenceExpression() CodeArgumentReferenceExpression()

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

CodeArgumentReferenceExpression(String) CodeArgumentReferenceExpression(String) CodeArgumentReferenceExpression(String) CodeArgumentReferenceExpression(String)

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

屬性

ParameterName ParameterName ParameterName ParameterName

取得或設定本運算式參考的參數名稱。Gets or sets the name of the parameter this expression references.

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)

適用於