InAttribute InAttribute InAttribute InAttribute Class

定义

指示应将数据从调用方封送到被调用方,而不返回到调用方。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)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class InAttribute : Attribute
type InAttribute = class
    inherit Attribute
Public NotInheritable Class InAttribute
Inherits Attribute
继承
InAttributeInAttributeInAttributeInAttribute
属性

示例

下面的示例演示如何应用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
{
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() {}
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

注解

可以将此特性应用于参数。You can apply this attribute to parameters.

InAttribute是可选的。The InAttribute is optional. 该属性支持 COM 互操作和平台调用仅。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. 例如,StringBuilder类始终假定为输入/输出和一个按值传递的字符串数组被假定为中。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到 C# 使用修改的参数-样式out关键字。You cannot apply the InAttribute to a parameter modified with the C#-styled out keyword. 为了避免混淆In在使用 Visual Basic 中的关键字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是特别有用时应用于数组和格式化,非 blittable 类型。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() InAttribute() InAttribute() InAttribute()

初始化 InAttribute 类的新实例。Initializes a new instance of the InAttribute class.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

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

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

属性

TypeId TypeId TypeId TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

适用于

另请参阅