Export (0) Print
Expand All

CodeParameterDeclarationExpression Class

Represents a parameter declaration for a method, property, or constructor.

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

System.Object
   System.CodeDom.CodeObject
      System.CodeDom.CodeExpression
         System.CodeDom.CodeParameterDeclarationExpression

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

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

CodeParameterDeclarationExpression can be used to represent code that declares a parameter for a method, property, or constructor.

The Name property specifies the name of the parameter. The Type property specifies the data type of the parameter. The Direction property specifies the direction modifier of the parameter. The CustomAttributes property specifies the attributes associated with the parameter.

Example

[Visual Basic, C#, C++] The following example demonstrates use of CodeParameterDeclarationExpression to declare parameters of a method using different FieldDirection field reference type specifiers.

[Visual Basic] 
' Declares a method.
Dim method1 As New CodeMemberMethod()
method1.Name = "TestMethod"

' Declares a string parameter passed by reference.
Dim param1 As New CodeParameterDeclarationExpression("System.String", "stringParam")
param1.Direction = FieldDirection.Ref
method1.Parameters.Add(param1)

' Declares a Int32 parameter passed by incoming field.
Dim param2 As New CodeParameterDeclarationExpression("System.Int32", "intParam")
param2.Direction = FieldDirection.Out
method1.Parameters.Add(param2)

' A Visual Basic code generator produces the following source code for the preceeding example code:
 
'     Private Sub TestMethod(ByRef stringParam As String, ByRef intParam As Integer)
'    End Sub

[C#] 
// Declares a method.
CodeMemberMethod method1 = new CodeMemberMethod();
method1.Name = "TestMethod";

// Declares a string parameter passed by reference.
CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression("System.String", "stringParam");
param1.Direction = FieldDirection.Ref;
method1.Parameters.Add(param1);

// Declares a Int32 parameter passed by incoming field.
CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression("System.Int32", "intParam");
param2.Direction = FieldDirection.Out;
method1.Parameters.Add(param2);

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

//        private void TestMethod(ref string stringParam, out int intParam) {
//        }

[C++] 
// Declares a method.
CodeMemberMethod* method1 = new CodeMemberMethod();
method1->Name = S"TestMethod";

// Declares a string parameter passed by reference.
CodeParameterDeclarationExpression* param1 = new CodeParameterDeclarationExpression(S"System.String", S"stringParam");
param1->Direction = FieldDirection::Ref;
method1->Parameters->Add(param1);

// Declares a Int32 parameter passed by incoming field.
CodeParameterDeclarationExpression* param2 = new CodeParameterDeclarationExpression(S"System.Int32", S"intParam");
param2->Direction = FieldDirection::Out;
method1->Parameters->Add(param2);

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

//        private void TestMethod(ref string stringParam, out int intParam) {
//        }

[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

CodeParameterDeclarationExpression Members | System.CodeDom Namespace | CodeParameterDeclarationExpressionCollection

Show:
© 2014 Microsoft