InAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指示应将数据从调用方封送给被调用方,但不应返回到调用方。
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 调用原型。 方向属性的组合允许调用方查看被调用方所做的更改。
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 修改的参数。 若要避免将 Visual Basic 中的关键字与InAttribute减号属性混淆In,请使用<[In]>带括号的窗体。
组合在InAttributeOutAttribute数组和格式化的非 blittable 类型时特别有用。 调用方仅当应用这两个属性时,才会看到被调用方对这些类型的更改。 由于这些类型需要在封送期间复制,因此可以使用 InAttribute 和 OutAttribute 减少不必要的副本。
构造函数
| 名称 | 说明 |
|---|---|
| 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) |