CodeMethodReturnStatement CodeMethodReturnStatement CodeMethodReturnStatement CodeMethodReturnStatement Class

Definition

Represents a return value statement.

public ref class CodeMethodReturnStatement : System::CodeDom::CodeStatement
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeMethodReturnStatement : System.CodeDom.CodeStatement
type CodeMethodReturnStatement = class
    inherit CodeStatement
Public Class CodeMethodReturnStatement
Inherits CodeStatement
Inheritance
CodeMethodReturnStatementCodeMethodReturnStatementCodeMethodReturnStatementCodeMethodReturnStatement
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() CodeMethodReturnStatement() CodeMethodReturnStatement() CodeMethodReturnStatement()

Initializes a new instance of the CodeMethodReturnStatement class.

CodeMethodReturnStatement(CodeExpression) CodeMethodReturnStatement(CodeExpression) CodeMethodReturnStatement(CodeExpression) CodeMethodReturnStatement(CodeExpression)

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

Properties

EndDirectives EndDirectives EndDirectives EndDirectives

Gets a CodeDirectiveCollection object that contains end directives.

(Inherited from CodeStatement)
Expression Expression Expression Expression

Gets or sets the return value.

LinePragma LinePragma LinePragma LinePragma

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

(Inherited from CodeStatement)
StartDirectives StartDirectives StartDirectives StartDirectives

Gets a CodeDirectiveCollection object that contains start directives.

(Inherited from CodeStatement)
UserData UserData UserData UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to