Compartilhar via


Classe OutAttribute

 

Indica que os dados devem passar por marshaling do receptor de volta ao chamador.

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (em mscorlib.dll)

Hierarquia de Herança

System.Object
  System.Attribute
    System.Runtime.InteropServices.OutAttribute

Sintaxe

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

Construtores

Nome Descrição
System_CAPS_pubmethod OutAttribute()

Inicializa uma nova instância da classe OutAttribute.

Propriedades

Nome Descrição
System_CAPS_pubproperty TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.(Herdado de Attribute.)

Métodos

Nome Descrição
System_CAPS_pubmethod Equals(Object)

Esta API dá suporte à infraestrutura produto e não se destina a ser usada diretamente do seu código. Retorna um valor que indica se essa instância é igual a um objeto especificado.(Herdado de Attribute.)

System_CAPS_pubmethod GetHashCode()

Retorna o código hash para essa instância.(Herdado de Attribute.)

System_CAPS_pubmethod GetType()

Obtém o Type da instância atual.(Herdado de Object.)

System_CAPS_pubmethod IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.(Herdado de Attribute.)

System_CAPS_pubmethod Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.(Herdado de Attribute.)

System_CAPS_pubmethod ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.(Herdado de Object.)

Implementações Explícitas da Interface

Nome Descrição
System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.(Herdado de Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.(Herdado de Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod _Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).(Herdado de Attribute.)

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

Fornece acesso a propriedades e métodos expostos por um objeto.(Herdado de Attribute.)

Comentários

You can apply this attribute to parameters.

The T:System.Runtime.InteropServices.OutAttribute 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.

Out-only behavior is never a default marshaling behavior for parameters. You can apply the T:System.Runtime.InteropServices.OutAttribute to value and reference types passed by reference to change In/Out behavior to Out-only behavior, which is equivalent to using the out keyword in C#. For example, arrays passed by value, marshaled as In-only parameters by default, can be changed to Out-only. However, the behavior does not always provide expected semantics when the types include all-blittable elements or fields because the interop marshaler uses pinning. If you do not care about passing data into the callee, Out-only marshaling can provide better performance for non-blittable types.

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.OutAttribute on marshaling behavior, see Directional Attributes.

Exemplos

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() {}

Informações de Versão

Plataforma Universal do Windows
Disponível desde 8
.NET Framework
Disponível desde 1.1
Biblioteca de Classes Portátil
Com suporte no: plataformas portáteis do .NET
Silverlight
Disponível desde 2.0
Windows Phone Silverlight
Disponível desde 7.0
Windows Phone
Disponível desde 8.1

Acesso thread-safe

Quaisquer membros estáticos públicos ( Compartilhado no Visual Basic) desse tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Confira Também

InAttribute
StringBuilder
Namespace System.Runtime.InteropServices
Tipos blittable e não blittable

Retornar ao início