Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ParameterInfo Class

Discovers the attributes of a parameter and provides access to parameter metadata.

System.Object
  System.Reflection.ParameterInfo

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

'Declaration
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.None)> _
Public Class ParameterInfo _
	Implements ICustomAttributeProvider

The ParameterInfo type exposes the following members.

  NameDescription
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ParameterInfoInitializes a new instance of the ParameterInfo class.
Top

  NameDescription
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360AttributesGets the attributes for this parameter.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360DefaultValueGets the default value, if the parameter has a default value.
Public propertyIsInGets a value indicating whether this is an input parameter.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsOptionalGets a value indicating whether this parameter is optional.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360IsOutGets a value indicating whether this is an output parameter.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360MemberGets the member in which the parameter is defined.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360MetadataTokenGets a value that identifies this parameter in metadata.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360NameGets the name of the parameter.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360ParameterTypeGets the type of this parameter.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360PositionGets the zero-based position of the parameter in the formal parameter list.
Public propertyRawDefaultValueGets a value indicating the default value if the parameter has a default value.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

In Silverlight for Windows Phone, this member is overridden by Equals(Object).


In XNA Framework, this member is overridden by Equals(Object).
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360FinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetCustomAttributes(Boolean)Gets all the custom attributes defined on this parameter.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetCustomAttributes(Type, Boolean)Gets the custom attributes of the specified type or its derived types that are applied to this parameter.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)

In Silverlight for Windows Phone, this member is overridden by GetHashCode.


In XNA Framework, this member is overridden by GetHashCode.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360IsDefinedDetermines whether the custom attribute of the specified type or its derived types is applied to this parameter.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToStringGets the parameter type and name represented as a string. (Overrides Object.ToString.)
Top

Use an instance of ParameterInfo to obtain information about the parameter's data type, default value, and so on.

MethodBase.GetParameters returns an array of ParameterInfo objects representing the parameters of a method, in order.

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


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.

This type is thread safe.

Community Additions

Show:
© 2017 Microsoft