ParameterAttributes Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Defines the attributes that can be associated with a parameter. These are defined in CorHdr.h.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration ParameterAttributes
[FlagsAttribute]
[ComVisibleAttribute(true)]
public enum ParameterAttributes

Members

Member name Description
Supported by Silverlight for Windows PhoneSupported by Xbox 360 None Specifies that there is no parameter attribute.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 In Specifies that the parameter is an input parameter.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Out Specifies that the parameter is an output parameter.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Retval Specifies that the parameter is a return value.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Optional Specifies that the parameter is optional.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 ReservedMask Specifies that the parameter is reserved.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 HasDefault Specifies that the parameter has a default value.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 HasFieldMarshal Specifies that the parameter has field marshaling information.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Reserved3 Reserved.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Reserved4 Reserved.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Lcid Specifies that the parameter is a locale identifier. Not supported. Present in Silverlight for Windows Phone.

Remarks

To get the ParameterAttributes value, first get the Type. From the Type, get the ParameterInfo array. The ParameterAttributes value is within the array.

These enumerator values are dependent on optional metadata. Not all attributes are available from all compilers. See the appropriate compiler instructions to determine which enumerated values are available.

Examples

The following example displays the attributes of four parameters.

Imports System.Reflection
Imports System.Runtime.InteropServices

Class Example

   Public Shared Sub mymethod(ByVal str1 As String, ByRef str2 As String, _
      <Out> ByRef str3 As String, <InAttribute> ByVal str4 As String)

      ' Add str1 to str2, which is ByRef.
      str2 &= str1
      ' When mymethod is called, str3 has no value. Give it one.
      str3 = "new value"
   End Sub

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) 

      ' Get the method.
      Dim mm As MethodInfo = GetType(Example).GetMethod("mymethod")

      ' Display the method.
      outputBlock.Text &= "MethodInfo.ToString(): " & mm.ToString() & vbCrLf

      For Each param In mm.GetParameters()

         outputBlock.Text &= String.Format("Attributes for parameter {0}, ""{1}"": {2} ({3})", _ 
            param.Position, param.Name, param.Attributes, CInt(param.Attributes))

         If param.ParameterType.IsByRef Then
            outputBlock.Text &= "; the parameter type is ByRef" & vbLf
         Else
            outputBlock.Text &= vbLf
         End If
      Next
   End Sub
End Class

' This code produces the following output:
'
'MethodInfo.ToString(): Void mymethod(System.String, System.String ByRef, System.String ByRef)
'Attributes for parameter 0, "str1": None (0)
'Attributes for parameter 1, "str2": None (0); the parameter type is ByRef
'Attributes for parameter 2, "str3": Out (2); the parameter type is ByRef
'Attributes for parameter 3, "str4": In (1)
using System;
using System.Reflection;
using System.Runtime.InteropServices;

class Example
{
   public static void mymethod(string str1, ref string str2, out string str3,
      [In] string str4)
   {
      // Concatenate str1 to str2, which is ref.
      str2 += str1;
      // When mymethod is called, str3 has no value. Give it one.
      str3 = "new value";
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      MethodInfo mm = typeof(Example).GetMethod("mymethod");

      // Display the method.
      outputBlock.Text += "MethodInfo.ToString(): " + mm.ToString() + "\n";

      // Get and display the attributes for the second parameter.
      foreach (ParameterInfo param in mm.GetParameters())
      {
         outputBlock.Text += String.Format("Attributes for parameter {0}, \"{1}\": {2} ({3})",  
            param.Position, param.Name, param.Attributes, (int)param.Attributes);

         if (param.ParameterType.IsByRef)
         {
            outputBlock.Text += "; the parameter type is ref\n";
         }
         else
         {
            outputBlock.Text += "\n";
         }
      }
   }
}

/* This code produces the following output:

MethodInfo.ToString(): Void mymethod(System.String, System.String ByRef, System.String ByRef)
Attributes for parameter 0, "str1": None (0)
Attributes for parameter 1, "str2": None (0); the parameter type is ByRef
Attributes for parameter 2, "str3": Out (2); the parameter type is ByRef
Attributes for parameter 3, "str4": In (1)
 */

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference