Compartir a través de


Clase InAttribute

 

Publicado: octubre de 2016

Indica que se debe hacer un cálculo de referencias de los datos desde el llamador al destinatario de la llamada, pero no de vuelta al llamador.

Espacio de nombres:   System.Runtime.InteropServices
Ensamblado:  mscorlib (en mscorlib.dll)

Jerarquía de herencia

System.Object
  System.Attribute
    System.Runtime.InteropServices.InAttribute

Sintaxis

[AttributeUsageAttribute(AttributeTargets.Parameter, Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class InAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Parameter, Inherited = false)]
[ComVisibleAttribute(true)]
public ref class InAttribute sealed : Attribute
[<Sealed>]
[<AttributeUsageAttribute(AttributeTargets.Parameter, Inherited = false)>]
[<ComVisibleAttribute(true)>]
type InAttribute = 
    class
        inherit Attribute
    end
<AttributeUsageAttribute(AttributeTargets.Parameter, Inherited := False)>
<ComVisibleAttribute(True)>
Public NotInheritable Class InAttribute
    Inherits Attribute

Constructores

Nombre Descripción
System_CAPS_pubmethod InAttribute()

Inicializa una nueva instancia de la clase InAttribute.

Propiedades

Nombre Descripción
System_CAPS_pubproperty TypeId

Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.(Heredado de Attribute).

Métodos

Nombre Descripción
System_CAPS_pubmethod Equals(Object)

Esta API admite la infraestructura producto y no está diseñada para usarse directamente desde el código. Devuelve un valor que indica si esta instancia es igual que un objeto especificado.(Heredado de Attribute).

System_CAPS_pubmethod GetHashCode()

Devuelve el código hash de esta instancia.(Heredado de Attribute).

System_CAPS_pubmethod GetType()

Obtiene el Type de la instancia actual.(Heredado de Object).

System_CAPS_pubmethod IsDefaultAttribute()

Si se reemplaza en una clase derivada, indica si el valor de esta instancia es el valor predeterminado de la clase derivada.(Heredado de Attribute).

System_CAPS_pubmethod Match(Object)

Cuando se invalida en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.(Heredado de Attribute).

System_CAPS_pubmethod ToString()

Devuelve una cadena que representa el objeto actual.(Heredado de Object).

Implementaciones de interfaz explícitas

Nombre Descripción
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.(Heredado de Attribute).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Obtiene la información de tipos de un objeto, que puede utilizarse para obtener la información de tipos de una interfaz.(Heredado de Attribute).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).(Heredado de Attribute).

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Proporciona acceso a las propiedades y los métodos expuestos por un objeto.(Heredado de Attribute).

Comentarios

You can apply this attribute to parameters.

The T:System.Runtime.InteropServices.InAttribute is optional. The attribute is supported for COM interop and platform invoke only. In the absence of explicit settings, the interop marshaler assumes rules based on the parameter type, whether the parameter is passed by reference or by value, and whether the type is blittable or non-blittable. For example, the T:System.Text.StringBuilder class is always assumed to be In/Out and an array of strings passed by value is assumed to be In.

You cannot apply the T:System.Runtime.InteropServices.InAttribute to a parameter modified with the C#-styled out keyword. To avoid confusing the In keyword in Visual Basic with the T:System.Runtime.InteropServices.InAttribute, minus Attribute, use the <[In]> form with brackets around the attribute.

Combining the T:System.Runtime.InteropServices.InAttribute and T:System.Runtime.InteropServices.OutAttribute is particularly useful when applied to arrays and formatted, non-blittable types. Callers see the changes a callee makes to these types only when you apply both attributes. Since these types require copying during marshaling, you can use T:System.Runtime.InteropServices.InAttribute and T:System.Runtime.InteropServices.OutAttribute to reduce unnecessary copies.

For more information on the effect of T:System.Runtime.InteropServices.InAttribute on marshaling behavior, see Directional Attributes.

Ejemplos

The following example shows how to apply the T:System.Runtime.InteropServices.InAttribute and T:System.Runtime.InteropServices.OutAttribute to a platform invoke prototype that passes an array as a parameter. The combination of directional attributes allows the caller to see the changes made by the callee.

using System.Runtime.InteropServices;
using System;


// Declare a class member for each structure element.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class OpenFileName
{
    public int structSize = 0;
    public string filter = null;
    public string file = null;
    // ...
}

public class LibWrap
{
    // Declare a managed prototype for the unmanaged function.
    [DllImport("Comdlg32.dll", CharSet = CharSet.Unicode)]
    public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
}

public class MainMethod
{
    static void Main()
    { }

}
Imports System.Runtime.InteropServices


' Declare a class member for each structure element.
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Class OpenFileName

   Public structSize As Integer = 0
   Public filter As String = Nothing
   Public file As String = Nothing
   ' ...

End Class 'OpenFileName

Public Class LibWrap
   ' Declare managed prototype for the unmanaged function.
   Declare Unicode Function GetOpenFileName Lib "Comdlg32.dll" ( _
      <[In](), Out()> ByVal ofn As OpenFileName) As Boolean
End Class 'LibWrap

Public Class App
    Public Shared Sub Main()

    End Sub 'Main
End Class 'App
using namespace System;
using namespace System::Runtime::InteropServices;


// Declare a class member for each structure element.

[StructLayout(LayoutKind::Sequential,CharSet=CharSet::Unicode)]
public ref class OpenFileName
{
public:
   int structSize;
   String^ filter;
   String^ file;
   // ...
};

public ref class LibWrap
{
public:

   // Declare a managed prototype for the unmanaged function.

   [DllImport("Comdlg32.dll",CharSet=CharSet::Unicode)]
   static bool GetOpenFileName( [In,Out]OpenFileName^ ofn );
};

void main() {}

Información de versión

Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 1.1
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Windows Phone
Disponible desde 8.1

Seguridad para subprocesos

Cualquier miembro ( Compartido en Visual Basic) estático público de este tipo es seguro para subprocesos. No se garantiza que los miembros de instancia sean seguros para subprocesos.

Ver también

OutAttribute
StringBuilder
Espacio de nombres System.Runtime.InteropServices
Blittable and Non-Blittable Types

Volver al principio