แก้ไข

แชร์ผ่าน


CodeMethodReturnStatement Class

Definition

Represents a return value statement.

public ref class CodeMethodReturnStatement : System::CodeDom::CodeStatement
public class CodeMethodReturnStatement : System.CodeDom.CodeStatement
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeMethodReturnStatement : System.CodeDom.CodeStatement
type CodeMethodReturnStatement = class
    inherit CodeStatement
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeMethodReturnStatement = class
    inherit CodeStatement
Public Class CodeMethodReturnStatement
Inherits CodeStatement
Inheritance
CodeMethodReturnStatement
Attributes

Examples

The following example demonstrates use of a CodeMethodReturnStatement to return a value from a method.

// Defines a method that returns a string passed to it.
CodeMemberMethod^ method1 = gcnew CodeMemberMethod;
method1->Name = "ReturnString";
method1->ReturnType = gcnew CodeTypeReference( "System.String" );
method1->Parameters->Add( gcnew CodeParameterDeclarationExpression( "System.String","text" ) );
method1->Statements->Add( gcnew CodeMethodReturnStatement( gcnew CodeArgumentReferenceExpression( "text" ) ) );

// A C# code generator produces the following source code for the preceeding example code:
//    private string ReturnString(string text) 
//    {
//        return text;
//    }
// Defines a method that returns a string passed to it.
CodeMemberMethod method1 = new CodeMemberMethod();
method1.Name = "ReturnString";
method1.ReturnType = new CodeTypeReference("System.String");
method1.Parameters.Add( new CodeParameterDeclarationExpression("System.String", "text") );
method1.Statements.Add( new CodeMethodReturnStatement( new CodeArgumentReferenceExpression("text") ) );

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

//    private string ReturnString(string text)
//    {
//        return text;
//    }
' Defines a method that returns a string passed to it.
Dim method1 As New CodeMemberMethod()
method1.Name = "ReturnString"
method1.ReturnType = New CodeTypeReference("System.String")
method1.Parameters.Add(New CodeParameterDeclarationExpression("System.String", "text"))
method1.Statements.Add(New CodeMethodReturnStatement(New CodeArgumentReferenceExpression("text")))

' A Visual Basic code generator produces the following source code for the preceeding example code:

'   Private Function ReturnString(ByVal [text] As String) As String
'       Return [Text]
'   End Function

Remarks

CodeMethodReturnStatement can be used to represent a return value statement. The Expression property specifies the value to return.

Constructors

CodeMethodReturnStatement()

Initializes a new instance of the CodeMethodReturnStatement class.

CodeMethodReturnStatement(CodeExpression)

Initializes a new instance of the CodeMethodReturnStatement class using the specified expression.

Properties

EndDirectives

Gets a CodeDirectiveCollection object that contains end directives.

(Inherited from CodeStatement)
Expression

Gets or sets the return value.

LinePragma

Gets or sets the line on which the code statement occurs.

(Inherited from CodeStatement)
StartDirectives

Gets a CodeDirectiveCollection object that contains start directives.

(Inherited from CodeStatement)
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