InAttribute 类

定义

指示数据应从调用方封送到被调用方,而不是从被调用方封送回调用方。

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
继承
InAttribute
属性

示例

以下示例演示如何将 和 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

注解

可以将此属性应用于参数。

InAttribute是可选的。 仅 COM 互操作和平台调用支持 属性。 在没有显式设置的情况下,互操作封送处理器会基于参数类型、参数是按引用传递还是按值传递,以及类型是 blittable 还是非 blittable。 例如, StringBuilder 类始终假定为 In/Out,值传递的字符串数组假定为 In。

不能将 应用于InAttribute使用 C# 样式out关键字 (keyword) 修改的参数。 若要避免将 In Visual Basic 中的关键字 (keyword) 与 InAttribute减去 属性混淆,请使用<[In]>带有属性括号的窗体。

InAttributeOutAttribute 组合在应用于数组和格式化的非 blittable 类型时特别有用。 调用方仅在应用这两个属性时,才会看到被调用方对这些类型所做的更改。 由于这些类型需要在封送处理期间复制,因此可以使用 InAttributeOutAttribute 来减少不必要的副本。

有关封送处理行为的影响的详细信息 InAttribute ,请参阅 方向属性

构造函数

InAttribute()

初始化 InAttribute 类的新实例。

属性

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)

适用于

另请参阅