InAttribute Classe

Definizione

Indica che il marshalling dei dati deve essere eseguito dal chiamante al chiamato, ma non di nuovo al chiamante.

public ref class InAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)]
public sealed class InAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class InAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)>]
type InAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type InAttribute = class
    inherit Attribute
Public NotInheritable Class InAttribute
Inherits Attribute
Ereditarietà
InAttribute
Attributi

Esempio

Nell'esempio seguente viene illustrato come applicare e InAttribute OutAttribute a un prototipo platform invoke che passa una matrice come parametro. La combinazione di attributi direzionali consente al chiamante di visualizzare le modifiche apportate dal chiamato.

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;
    // ...
};

private ref class NativeMethods
{
public:

    // Declare a managed prototype for the unmanaged function.

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

void main() {}
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;
    // ...
}

internal static class NativeMethods
{
    // Declare a managed prototype for the unmanaged function.
    [DllImport("Comdlg32.dll", CharSet = CharSet.Unicode)]
    internal 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

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

Public Class App
    Public Shared Sub Main()

    End Sub
End Class

Commenti

È possibile applicare questo attributo ai parametri.

è InAttribute facoltativo. L'attributo è supportato solo per l'interoperabilità COM e platform invoke. In assenza di impostazioni esplicite, il gestore di marshalling di interoperabilità presuppone regole basate sul tipo di parametro, se il parametro viene passato per riferimento o per valore e se il tipo è copiabile o non copiabile. Ad esempio, si presuppone che la StringBuilder classe sia sempre In/Out e si presuppone che una matrice di stringhe passate per valore sia In.

Non è possibile applicare a InAttribute un parametro modificato con la parola chiave C# out . Per evitare di confondere la In parola chiave in Visual Basic con l'attributo InAttribute, meno, usare il <[In]> form con parentesi quadre intorno all'attributo.

La combinazione di InAttribute e OutAttribute è particolarmente utile quando viene applicata alle matrici e ai tipi non copiabili formattati. I chiamanti visualizzano le modifiche apportate da un chiamato a questi tipi solo quando si applicano entrambi gli attributi. Poiché questi tipi richiedono la copia durante il marshalling, è possibile usare InAttribute e OutAttribute ridurre le copie non necessarie.

Per altre informazioni sull'effetto del comportamento di InAttribute marshalling, vedere Attributi direzionali.

Costruttori

InAttribute()

Inizializza una nuova istanza della classe InAttribute.

Proprietà

TypeId

Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute.

(Ereditato da Attribute)

Metodi

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
GetHashCode()

Restituisce il codice hash per l'istanza.

(Ereditato da Attribute)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

In caso di override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata.

(Ereditato da Attribute)
Match(Object)

Quando è sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza equivale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso a proprietà e metodi esposti da un oggetto.

(Ereditato da Attribute)

Si applica a

Vedi anche