OutAttribute クラス

定義

呼び出し先から呼び出し元へ、データをマーシャリングすることを示します。

public ref class OutAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)]
public sealed class OutAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class OutAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)>]
type OutAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type OutAttribute = class
    inherit Attribute
Public NotInheritable Class OutAttribute
Inherits Attribute
継承
OutAttribute
属性

次の例は、配列をパラメーターとして渡すプラットフォーム呼び出しOutAttributeプロトタイプを適用InAttributeする方法を示しています。 方向属性の組み合わせにより、呼び出し元は呼び出し先によって行われた変更を確認できます。

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

注釈

この属性はパラメーターに適用できます。

これは OutAttribute 省略可能です。 この属性は、COM 相互運用機能とプラットフォーム呼び出しでのみサポートされています。 明示的な設定がない場合、相互運用マーシャラーは、パラメーターの型、パラメーターが参照または値によって渡されるかどうか、および型が blittable か非 blittable かに基づいてルールを前提としています。 たとえば、 StringBuilder クラスは常に In/Out と見なされ、値によって渡される文字列の配列は In と見なされます。

アウトのみの動作は、パラメーターの既定のマーシャリング動作になることはありません。 参照によって渡された to 値と参照型を OutAttribute 適用して、In/Out 動作を Out のみの動作に変更できます。これは、C# でキーワードを out 使用することと同じです。 たとえば、既定では In-only パラメーターとしてマーシャリングされた値で渡される配列は、Out-only に変更できます。 ただし、相互運用マーシャラーはピン留めを使用するため、型に all-blittable 要素またはフィールドが含まれている場合、この動作では常に予期されるセマンティクスが提供されるとは限りません。 呼び出し先にデータを渡すことを気にしない場合は、Out-only マーシャリングによって、blittable 以外の型のパフォーマンスが向上する可能性があります。

InAttribute配列やOutAttribute書式設定された非 blittable 型に適用する場合に特に便利です。 呼び出し元は、両方の属性を適用した場合にのみ、呼び出し先がこれらの型に加える変更を確認します。 これらの型はマーシャリング中にコピーを必要とするため、不要なコピーを使用 InAttribute して OutAttribute 削減できます。

マーシャリング動作への影響の OutAttribute 詳細については、「 方向属性」を参照してください。

コンストラクター

OutAttribute()

OutAttribute クラスの新しいインスタンスを初期化します。

プロパティ

TypeId

派生クラスで実装されると、この Attribute の一意の識別子を取得します。

(継承元 Attribute)

メソッド

Equals(Object)

このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。

(継承元 Attribute)
GetHashCode()

このインスタンスのハッシュ コードを返します。

(継承元 Attribute)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
Match(Object)

派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

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

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象

こちらもご覧ください