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
屬性

範例

以下範例展示了如何將 and 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 互通與平台調用。 在缺乏明確設定的情況下,互通指令器假設規則基於參數類型、參數是透過參考傳遞還是以值傳遞,以及該類型是可位塊傳輸還是不可位移位塊。 例如, StringBuilder 類別總是假設為 In/Out,而由 value 傳遞的字串陣列則假設為 In。

僅輸出行為從來不是參數預設的編組行為。 你可以套用 OutAttribute to 值和參考類型,將 In/Out 行為改成僅 Out-的行為,這相當於在 C# 中使用 out 關鍵字。 例如,預設以 Value 參數編組為僅 In-Value 的陣列,可以改為僅 Out-。 然而,當類型包含所有可位塊元素或欄位時,行為並不總是提供預期的語意,因為互通化的 marshaler 使用釘定(pinning)。 如果你不在意將資料傳入被被請求者,僅輸出的分組對於不可位移型態能提供更好的效能。

結合 InAttributeOutAttribute 在用於陣列及格式化且不可位塊分析的類型時特別有用。 來電者只有在你同時套用這兩種屬性時,才能看到被叫者對這些類型所做的改變。 由於這些類型在調度時需要複製,你可以利用 InAttributeOutAttribute 減少不必要的複製。

建構函式

名稱 Description
OutAttribute()

初始化 OutAttribute 類別的新執行個體。

屬性

名稱 Description
TypeId

在衍生類別中實作時,取得這個 Attribute的唯一標識碼。

(繼承來源 Attribute)

方法

名稱 Description
Equals(Object)

傳回值,這個值表示這個實例是否等於指定的物件。

(繼承來源 Attribute)
GetHashCode()

傳回這個實例的哈希碼。

(繼承來源 Attribute)
GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取 物件的型別資訊,可用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱