CodeMethodReferenceExpression Constructors

Definition

Initializes a new instance of the CodeMethodReferenceExpression class.

Overloads

CodeMethodReferenceExpression()

Initializes a new instance of the CodeMethodReferenceExpression class.

CodeMethodReferenceExpression(CodeExpression, String)

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

CodeMethodReferenceExpression(CodeExpression, String, CodeTypeReference[])

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

CodeMethodReferenceExpression()

Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs

Initializes a new instance of the CodeMethodReferenceExpression class.

C#
public CodeMethodReferenceExpression();

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.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

CodeMethodReferenceExpression(CodeExpression, String)

Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs

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

C#
public CodeMethodReferenceExpression(System.CodeDom.CodeExpression targetObject, string methodName);

Parameters

targetObject
CodeExpression

A CodeExpression that indicates the object to target.

methodName
String

The name of the method to call.

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.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

CodeMethodReferenceExpression(CodeExpression, String, CodeTypeReference[])

Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs
Source:
codemethodreferenceexpression.cs

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

C#
public CodeMethodReferenceExpression(System.CodeDom.CodeExpression targetObject, string methodName, params System.CodeDom.CodeTypeReference[] typeParameters);

Parameters

targetObject
CodeExpression

A CodeExpression that indicates the object to target.

methodName
String

The name of the method to call.

typeParameters
CodeTypeReference[]

An array of CodeTypeReference values that specify the TypeArguments for this CodeMethodReferenceExpression.

Examples

The following code example shows the use of this constructor.

C#
using System;
using System.CodeDom;
using System.CodeDom.Compiler;

public class CodeGenExample
{
    static void Main()
    {
        // Declare a new type called Class1.
        CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1");

        // Declares a type constructor that calls a method.
        CodeConstructor constructor1 = new CodeConstructor();
        constructor1.Attributes = MemberAttributes.Public;
        class1.Members.Add( constructor1 );

        // Creates a method reference for dict.Init.
        CodeMethodReferenceExpression methodRef1 =
            new CodeMethodReferenceExpression(
                new CodeVariableReferenceExpression("dict"),
                "Init",
                new CodeTypeReference[] {
                    new CodeTypeReference("System.Decimal"),
                    new CodeTypeReference("System.Int32")});

        // Invokes the dict.Init method from the constructor.
        CodeMethodInvokeExpression invoke1 = new CodeMethodInvokeExpression( methodRef1, new CodeParameterDeclarationExpression[] {} );
        constructor1.Statements.Add( invoke1 );

        // Create a C# code provider
        CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

        // Generate code and send the output to the console
        provider.GenerateCodeFromType(class1, Console.Out, new CodeGeneratorOptions());
    }
}

// The C# code generator produces the following source code for the preceeding example code:
//
// public class Class1 {
//
//     public Class1() {
//         dict.Init<decimal, int>();
//     }
// }

Remarks

The typeParameters parameter represents a collection of type references to be substituted for the type parameter references of the current generic method.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 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