다음을 통해 공유


CodeMethodReferenceExpression 생성자

정의

CodeMethodReferenceExpression 클래스의 새 인스턴스를 초기화합니다.

오버로드

CodeMethodReferenceExpression()

CodeMethodReferenceExpression 클래스의 새 인스턴스를 초기화합니다.

CodeMethodReferenceExpression(CodeExpression, String)

지정된 대상 개체와 메서드 이름을 사용하여 CodeMethodReferenceExpression 클래스의 새 인스턴스를 초기화합니다.

CodeMethodReferenceExpression(CodeExpression, String, CodeTypeReference[])

지정된 대상 개체, 메서드 이름 및 제네릭 형식 인수를 사용하여 CodeMethodReferenceExpression 클래스의 새 인스턴스를 초기화합니다.

CodeMethodReferenceExpression()

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

CodeMethodReferenceExpression 클래스의 새 인스턴스를 초기화합니다.

public:
 CodeMethodReferenceExpression();
public CodeMethodReferenceExpression ();
Public Sub New ()

적용 대상

CodeMethodReferenceExpression(CodeExpression, String)

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

지정된 대상 개체와 메서드 이름을 사용하여 CodeMethodReferenceExpression 클래스의 새 인스턴스를 초기화합니다.

public:
 CodeMethodReferenceExpression(System::CodeDom::CodeExpression ^ targetObject, System::String ^ methodName);
public CodeMethodReferenceExpression (System.CodeDom.CodeExpression targetObject, string methodName);
new System.CodeDom.CodeMethodReferenceExpression : System.CodeDom.CodeExpression * string -> System.CodeDom.CodeMethodReferenceExpression
Public Sub New (targetObject As CodeExpression, methodName As String)

매개 변수

targetObject
CodeExpression

대상 개체를 나타내는 CodeExpression입니다.

methodName
String

호출할 메서드의 이름입니다.

추가 정보

적용 대상

CodeMethodReferenceExpression(CodeExpression, String, CodeTypeReference[])

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

지정된 대상 개체, 메서드 이름 및 제네릭 형식 인수를 사용하여 CodeMethodReferenceExpression 클래스의 새 인스턴스를 초기화합니다.

public:
 CodeMethodReferenceExpression(System::CodeDom::CodeExpression ^ targetObject, System::String ^ methodName, ... cli::array <System::CodeDom::CodeTypeReference ^> ^ typeParameters);
public CodeMethodReferenceExpression (System.CodeDom.CodeExpression targetObject, string methodName, params System.CodeDom.CodeTypeReference[] typeParameters);
new System.CodeDom.CodeMethodReferenceExpression : System.CodeDom.CodeExpression * string * System.CodeDom.CodeTypeReference[] -> System.CodeDom.CodeMethodReferenceExpression
Public Sub New (targetObject As CodeExpression, methodName As String, ParamArray typeParameters As CodeTypeReference())

매개 변수

targetObject
CodeExpression

대상 개체를 나타내는 CodeExpression입니다.

methodName
String

호출할 메서드의 이름입니다.

typeParameters
CodeTypeReference[]

CodeTypeReferenceTypeArguments를 지정하는 CodeMethodReferenceExpression 값의 배열입니다.

예제

다음 코드 예제에서는이 생성자의 사용을 보여 줍니다.

#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::CodeDom;
using namespace System::CodeDom::Compiler;

int main()
{
    // Declare a new type called Class1.
    CodeTypeDeclaration^ class1 = gcnew CodeTypeDeclaration("Class1");

    // Declares a type constructor that calls a method.
    CodeConstructor^ constructor1 = gcnew CodeConstructor();
    constructor1->Attributes = MemberAttributes::Public;
    class1->Members->Add(constructor1);

    // Creates a method reference for dict.Init.
    CodeMethodReferenceExpression^ methodRef1 =
        gcnew CodeMethodReferenceExpression(
            gcnew CodeVariableReferenceExpression("dict"),
            "Init",
            gcnew array<CodeTypeReference^> {
                gcnew CodeTypeReference("System.Decimal"),
                gcnew CodeTypeReference("System.Int32")});

    // Invokes the dict.Init method from the constructor.
    CodeMethodInvokeExpression^ invoke1 =
        gcnew CodeMethodInvokeExpression(methodRef1, gcnew array<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, gcnew CodeGeneratorOptions());
}

// The CPP code generator produces the following source code for the preceeding example code:
//
//public class Class1 {
//
//     public Class1() {
//         dict.Init<decimal, int>();
//     }
// }
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>();
//     }
// }
Imports System.CodeDom
Imports System.CodeDom.Compiler

Public Class CodeGenExample

    Shared Sub Main
        ' Declare a new type called Class1.
        Dim class1 as New CodeTypeDeclaration("Class1")

        ' Declares a type constructor that calls a method.
        Dim constructor1 As New CodeConstructor()
        constructor1.Attributes = MemberAttributes.Public
        class1.Members.Add( constructor1 )

        ' Creates a method reference for dict.Init.
        Dim methodRef1 as New CodeMethodReferenceExpression(
            New CodeVariableReferenceExpression("dict"),
            "Init",
            New CodeTypeReference() {
                New CodeTypeReference("System.Decimal"),
                New CodeTypeReference("System.Int32")})

        ' Invokes the dict.Init method from the constructor.
        Dim invoke1 As New CodeMethodInvokeExpression( methodRef1, new CodeParameterDeclarationExpression() {} )
        constructor1.Statements.Add( invoke1 )

        ' Create a Visual Basic code provider
        Dim provider As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic")

        ' Generate code and send the output to the console
        provider.GenerateCodeFromType(class1, Console.Out, New CodeGeneratorOptions())
    End Sub

End Class

' The Visual Basic code generator produces the following source code for the preceeding example code:
'
' Public Class Class1
'
'     Public Sub New()
'         MyBase.New
'         dict.Init(Of Decimal, Integer)
'     End Sub
' End Class'

설명

매개 변수는 typeParameters 현재 제네릭 메서드의 형식 매개 변수 참조로 대체될 형식 참조의 컬렉션을 나타냅니다.

적용 대상