Partager via


ParameterInfo.IsOut Property

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

Gets a value indicating whether this is an output parameter.

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

Syntax

'Declaration
Public ReadOnly Property IsOut As Boolean
public bool IsOut { get; }

Property Value

Type: System.Boolean
true if the parameter is an output parameter; otherwise, false.

Remarks

This method depends on an optional metadata flag. This flag can be inserted by compilers, but compilers are not obligated to do so.

This method uses the Out member of the ParameterAttributes enumeration.

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

Examples

The following example shows how to test method parameters for the ParameterAttributes.Out attribute.

The example contains a method named mymethod that has three parameters. The first parameter has no attributes, the second is an out parameter (OutAttributeByRef parameter in Visual Basic), and the third is a ref parameter (ByRef parameter in Visual Basic).

The example lists the parameters of mymethod, using the IsOut property to test each one for the ParameterAttributes.Out attribute.

Imports System.Reflection
Imports System.Runtime.InteropServices

Class Example

   Public Shared Sub mymethod(ByVal int1m As Integer, <Out> ByRef str2m As String, _
                              ByRef str3m As String)
      str2m = "in mymethod"
   End Sub

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

      outputBlock.Text &= "Reflection.Parameterinfo" & vbCrLf

      'Get the type.
      Dim Mytype As Type = GetType(Example)

      'Get and display the method.
      Dim Mymethodbase As MethodBase = Mytype.GetMethod("mymethod")
      outputBlock.Text &= "Mymethodbase = " & Mymethodbase.ToString() & vbLf

      'Get the ParameterInfo array.
      Dim Myarray As ParameterInfo() = Mymethodbase.GetParameters()

      'Get and display the IsOut of each parameter.
      Dim Myparam As ParameterInfo
      For Each Myparam In Myarray
         outputBlock.Text &= "For parameter # " & Myparam.Position.ToString() _
            & ", the value of IsOut is - " & Myparam.IsOut.ToString() & vbLf
      Next Myparam
      Return 0
   End Function
End Class

' This code produces the following output:
'
' Reflection.ParameterInfo
'  
' Mymethodbase = Void mymethod (Int32, System.String ByRef, System.String ByRef)
' For parameter # 0, the value of IsOut is - False
' For parameter # 1, the value of IsOut is - True
' For parameter # 2, the value of IsOut is - False 
using System;
using System.Reflection;

class Example
{
   public static void mymethod(
      int int1m, out string str2m, ref string str3m)
   {
      str2m = "in mymethod";
   }

   public static int Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "\nReflection.Parameterinfo" + "\n";

      //Get the ParameterInfo parameter of a function.

      //Get the type.
      Type Mytype = Type.GetType("Example");

      //Get and display the method.
      MethodBase Mymethodbase = Mytype.GetMethod("mymethod");
      outputBlock.Text += "\nMymethodbase = " + Mymethodbase;

      //Get the ParameterInfo array.
      ParameterInfo[] Myarray = Mymethodbase.GetParameters();

      //Get and display the IsOut of each parameter.
      foreach (ParameterInfo Myparam in Myarray)
      {
         outputBlock.Text += "\nFor parameter # " + Myparam.Position
            + ", the IsOut is - " + Myparam.IsOut;
      }
      return 0;
   }
}
/*
This code produces the following output:

Reflection.ParameterInfo

Mymethodbase = Void mymethod (Int32, System.String ByRef, System.String ByRef)
For parameter # 0, the IsOut is - False
For parameter # 1, the IsOut is - True
For parameter # 2, the IsOut is - False
*/

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.