Przeczytaj w języku angielskim Edytuj

Udostępnij za pośrednictwem


CodeMethodReferenceExpression Class

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Represents a reference to a method.

C#
public class CodeMethodReferenceExpression : System.CodeDom.CodeExpression
C#
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeMethodReferenceExpression : System.CodeDom.CodeExpression
Inheritance
CodeMethodReferenceExpression
Attributes

Examples

The following code example uses a CodeMethodReferenceExpression to refer to a method:

C#
// Invokes the TestMethod method of the current type object.
CodeMethodReferenceExpression methodRef1 = new CodeMethodReferenceExpression( new CodeThisReferenceExpression(), "TestMethod" );
CodeMethodInvokeExpression invoke1 = new CodeMethodInvokeExpression( methodRef1, new CodeParameterDeclarationExpression[] {} );

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

//        this.TestMethod();

Remarks

A CodeMethodReferenceExpression can be used to represent an expression of the form Object.Method.

The TargetObject property indicates the object that contains the method. The MethodName property indicates the name of the method.

A CodeMethodReferenceExpression is used with a CodeMethodInvokeExpression to indicate the method to invoke, and with a CodeDelegateCreateExpression to indicate the method to handle the event.

Constructors

CodeMethodReferenceExpression()

Initializes a new instance of the CodeMethodReferenceExpression class.

CodeMethodReferenceExpression(CodeExpression, String, CodeTypeReference[])

Initializes a new instance of the CodeMethodReferenceExpression class using the specified target object, method name, and generic type arguments.

CodeMethodReferenceExpression(CodeExpression, String)

Initializes a new instance of the CodeMethodReferenceExpression class using the specified target object and method name.

Properties

MethodName

Gets or sets the name of the method to reference.

TargetObject

Gets or sets the expression that indicates the method to reference.

TypeArguments

Gets the type arguments for the current generic method reference expression.

UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

Produkt Wersje
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.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
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10