InAttribute 類別


表示資料應從呼叫端封送處理至被呼叫端,但不會封送處理回呼叫端。Indicates that data should be marshaled from the caller to the callee, but not back to the caller.

public ref class InAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Parameter, Inherited=false)]
public sealed class InAttribute : Attribute
type InAttribute = class
    inherit Attribute
Public NotInheritable Class InAttribute
Inherits Attribute


下列範例示範如何將 InAttributeOutAttribute 套用至將陣列當做參數傳遞的平台叫用原型。The following example shows how to apply the InAttribute and 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 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
    int structSize;
    String^ filter;
    String^ file;
    // ...

private ref class NativeMethods

    // 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


您可以將此屬性套用至參數。You can apply this attribute to parameters.

InAttribute 是選擇性的。The InAttribute is optional. 僅支援 COM Interop 和平台叫用的屬性。The attribute is supported for COM interop and platform invoke only. 在沒有明確設定的情況下,interop 封送處理器會根據參數類型來假設規則、參數是以傳址方式或依值傳遞,以及該類型是以全像是或非直接的方式。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. 例如,StringBuilder 類別一律假設為 In/Out,而以傳值方式傳遞的字串陣列則假設為。For example, the StringBuilder class is always assumed to be In/Out and an array of strings passed by value is assumed to be In.

您無法將 InAttribute 套用至使用-樣式 out 關鍵字C#所修改的參數。You cannot apply the InAttribute to a parameter modified with the C#-styled out keyword. 若要避免混淆 Visual Basic 中的 In 關鍵字與 InAttribute,減號屬性,請在屬性前後使用 <[In]> 表單加上方括弧。To avoid confusing the In keyword in Visual Basic with the InAttribute, minus Attribute, use the <[In]> form with brackets around the attribute.

InAttributeOutAttribute 結合在套用至陣列和格式化的非類型的類型時,特別有用。Combining the InAttribute and 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. 因為這些類型需要在封送處理期間複製,所以您可以使用 InAttributeOutAttribute 來減少不必要的複本。Since these types require copying during marshaling, you can use InAttribute and OutAttribute to reduce unnecessary copies.

如需有關封送處理行為 InAttribute 效果的詳細資訊,請參閱方向屬性For more information on the effect of InAttribute on marshaling behavior, see Directional Attributes.



初始化 InAttribute 類別的新執行個體。Initializes a new instance of the InAttribute class.



在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(繼承來源 Attribute)



傳回值,這個值指出此執行個體是否與指定的物件相等。Returns a value that indicates whether this instance is equal to a specified object.

(繼承來源 Attribute)

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

(繼承來源 Attribute)

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(繼承來源 Attribute)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(繼承來源 Attribute)

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)


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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

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

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

(繼承來源 Attribute)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

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

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(繼承來源 Attribute)