Export (0) Print
Expand All
Expand Minimize

ParameterAttributes Enumeration

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)

[FlagsAttribute]
[ComVisibleAttribute(true)]
public enum ParameterAttributes

Member nameDescription
Supported by Silverlight for Windows PhoneSupported by Xbox 360NoneSpecifies that there is no parameter attribute.
Supported by Silverlight for Windows PhoneSupported by Xbox 360InSpecifies that the parameter is an input parameter.
Supported by Silverlight for Windows PhoneSupported by Xbox 360OutSpecifies that the parameter is an output parameter.
Supported by Silverlight for Windows PhoneSupported by Xbox 360RetvalSpecifies that the parameter is a return value.
Supported by Silverlight for Windows PhoneSupported by Xbox 360OptionalSpecifies that the parameter is optional.
Supported by Silverlight for Windows PhoneSupported by Xbox 360ReservedMaskSpecifies that the parameter is reserved.
Supported by Silverlight for Windows PhoneSupported by Xbox 360HasDefaultSpecifies that the parameter has a default value.
Supported by Silverlight for Windows PhoneSupported by Xbox 360HasFieldMarshalSpecifies that the parameter has field marshaling information.
Supported by Silverlight for Windows PhoneSupported by Xbox 360Reserved3Reserved.
Supported by Silverlight for Windows PhoneSupported by Xbox 360Reserved4Reserved.
Supported by Silverlight for Windows PhoneSupported by Xbox 360LcidSpecifies that the parameter is a locale identifier. Not supported. Present in Silverlight for Windows Phone.

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.

The following example displays the attributes of four parameters.


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)
 */


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

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

Community Additions

ADD
Show:
© 2014 Microsoft