This documentation is archived and is not being maintained.

CodeMemberMethod Class

Represents a declaration for a method of a type.

For a list of all members of this type, see CodeMemberMethod Members.

System.Object
   System.CodeDom.CodeObject
      System.CodeDom.CodeTypeMember
         System.CodeDom.CodeMemberMethod
            System.CodeDom.CodeConstructor
            System.CodeDom.CodeEntryPointMethod
            System.CodeDom.CodeTypeConstructor

[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ComVisible(True)>
Public Class CodeMemberMethod
   Inherits CodeTypeMember
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class CodeMemberMethod : CodeTypeMember
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ComVisible(true)]
public __gc class CodeMemberMethod : public CodeTypeMember
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDispatch)
 ComVisible(true)
class CodeMemberMethod extends CodeTypeMember

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

CodeMemberMethod can be used to represent the declaration for a method.

The ReturnType property specifies the data type of the method's return value. The Parameters property contains the method's parameters. The Statements property contains the statements of the method.

Example

[Visual Basic, C#, C++] The following example demonstrates use of a CodeMemberMethod to declare a method that accepts a parameter and returns a value.

[Visual Basic] 
' 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

[C#] 
// 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;
//    }

[C++] 
// Defines a method that returns a string passed to it.
CodeMemberMethod* method1 = new CodeMemberMethod();            
method1->Name = S"ReturnString";
method1->ReturnType = new CodeTypeReference(S"System.String");
method1->Parameters->Add( new CodeParameterDeclarationExpression(S"System.String", S"text") );
method1->Statements->Add( new CodeMethodReturnStatement( new CodeArgumentReferenceExpression(S"text") ) );            

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

//    private string ReturnString(string text) 
//    {
//        return text;
//    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.CodeDom

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

CodeMemberMethod Members | System.CodeDom Namespace

Show: