Attributes Property

ParameterInfo.Attributes Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets the attributes for this parameter.

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

public virtual ParameterAttributes Attributes { get; }

Property Value

Type: System.Reflection.ParameterAttributes
The attributes for this parameter.

To get the ParameterInfo array, first get the method or the constructor, and then call MethodBase.GetParameters.

The following example defines a method with four parameters and uses the Attributes property to display the attributes of the 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";
            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)

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft