ParameterInfo.Attributes Property

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
A ParameterAttributes object representing the attributes for this parameter.

This method utilizes the AttrsImpl method.

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

The following example defines a method with three parameters. It uses the Attributes property to get the attributes of the second parameter and display them at the console.

using System;
using System.Reflection;
public class MyClass1
{
   public int MyMethod( int i, out short j, ref long k)
   {
      j = 2;
      return 0;
   }  
}

public class ParameterInfo_Attributes
{   
   public static void Main()
   {
      // Get the type. 
      Type myType = typeof(MyClass1);
      // Get the method named 'MyMethod' from the type.
      MethodBase myMethodBase = myType.GetMethod("MyMethod");
      // Get the parameters associated with the method.
      ParameterInfo[] myParameters = myMethodBase.GetParameters();
      Console.WriteLine("\nThe method {0} has the {1} parameters :", 
                          "ParameterInfo_Example.MyMethod", myParameters.Length);
      // Print the attributes associated with each of the parameters. 
      for(int i = 0; i < myParameters.Length; i++)
         Console.WriteLine("\tThe {0} parameter has the attribute : {1}", 
                                             i + 1, myParameters[i].Attributes);
   }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft