ParameterInfo.IsOut Propiedad

Definición

Obtiene un valor que indica si este es un parámetro de salida.

C#
public bool IsOut { get; }

Valor de propiedad

true si el parámetro es un parámetro de salida; en caso contrario, false.

Ejemplos

En el ejemplo siguiente se muestra cómo probar parámetros de método para los ParameterAttributes.Inatributos , ParameterAttributes.Outy ParameterAttributes.Optional .

El ejemplo contiene un DefineMethod método que hace lo siguiente:

Después de DefineMethodejecutar , el ejemplo busca en los ensamblados que se cargan actualmente hasta que encuentre el ensamblado dinámico. Se carga MyType desde el ensamblado, obtiene un MethodInfo objeto para el MyMethod método y examina los parámetros. En el ejemplo se usan las IsInpropiedades , IsOuty IsOptional para mostrar información sobre los parámetros.

C#
using System;
using System.Reflection;

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

    public static int Main(string[] args)
    {
       Console.WriteLine("\nReflection.Parameterinfo");

       //Get the ParameterInfo parameter of a function.

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

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

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

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

 Reflection.ParameterInfo

 Mymethodbase = Void mymethod (int, 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
 */

Comentarios

Este método depende de una marca de metadatos opcional. Los compiladores pueden insertar esta marca, pero los compiladores no están obligados a hacerlo.

Este método utiliza la Out marca del ParameterAttributes enumerador.

Para obtener la ParameterInfo matriz, primero obtenga el método o el constructor y, a continuación, llame a MethodBase.GetParameters.

Se aplica a

Produto Versións
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0