CodeArgumentReferenceExpression 類別

定義

代表傳遞至方法之引數值的參考。

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

範例

下列範例程式代碼會定義叫用 方法, Console.WriteLine 以輸出傳遞至 方法的字串參數。 會 CodeArgumentReferenceExpression 參考依方法參數名稱傳遞至方法的自變數。

// 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 可用於方法,以參考已傳遞至 方法的參數值。

屬性 ParameterName 會指定要參考的參數名稱。

建構函式

CodeArgumentReferenceExpression()

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

CodeArgumentReferenceExpression(String)

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

屬性

ParameterName

取得或設定本運算式參考的參數名稱。

UserData

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

(繼承來源 CodeObject)

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

適用於