InAttribute クラスとは? わかりやすく解説

InAttribute クラス

呼び出し元から呼び出し先へデータマーシャリングするが、逆方向にはマーシャリングしないことを示します

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<AttributeUsageAttribute(AttributeTargets.Parameter, Inherited:=False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 InAttribute
    Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Parameter, Inherited=false)]
 
[ComVisibleAttribute(true)] 
public sealed class InAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Parameter, Inherited=false)]
 
[ComVisibleAttribute(true)] 
public ref class InAttribute sealed : public
 Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Parameter, Inherited=false)
 */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class InAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Parameter, Inherited=false)
 
ComVisibleAttribute(true) 
public final class InAttribute extends
 Attribute
解説解説

この属性は、パラメータ適用できます

InAttributeオプションです。この属性は、COM 相互運用、およびプラットフォーム呼び出しのときにだけ使用できます明示的な設定ない場合相互運用マーシャラは、パラメータの型 (パラメータ参照渡し値渡しか、型が blittable か非 blittable か) に応じて規則判断します。たとえば、StringBuilder クラスは常に In/Out として扱われ値渡しされた文字列配列は In として扱われます。

C# スタイルout キーワードで修飾されパラメータInAttribute適用することはできません。Visual BasicIn キーワードと、InAttribute から Attribute取り除かれ場合区別するために、属性前後には <[In]> のようにかっこを付けてください

InAttribute と OutAttribute を組み合わせると、配列型および書式付きの非 blittable 型に適用する場合に、特に役立ちます両方属性適用した場合にだけ、呼び出し元は、呼び出し先がこれらの型に対して加えた変更参照できます。これらの型はマーシャリング中にコピー要求するため、InAttributeOutAttribute使用して不要なコピーを減らすことができます

マーシャリング動作InAttribute与え影響詳細については、「方向属性」を参照してください

使用例使用例

パラメータとして配列を渡すプラットフォーム呼び出しプロトタイプInAttributeOutAttribute適用する例を次に示します方向属性組み合わせ使用すると、呼び出し元は呼び出し先によって加えられ変更確認できます

' Declare a class member for each structure element.
< StructLayout( LayoutKind.Sequential, CharSet:=CharSet.Auto )> _
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 Auto Function
 GetOpenFileName Lib "Comdlg32.dll"
 ( _
      <[In], Out> ByVal ofn As OpenFileName
 ) As Boolean
End Class 'LibWrap
// Declare a class member for each structure element.
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]  
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.Auto )]
   public static extern bool
 GetOpenFileName([ In, Out ] OpenFileName ofn );  
}
// Declare a class member for each structure element.

[StructLayout(LayoutKind::Sequential,CharSet=CharSet::Auto)]
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::Auto)]
   static bool GetOpenFileName( [In,Out]OpenFileName^
 ofn );
};

// Declare a class member for each structure element.
/** @attribute StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)
 */
public class OpenFileName
{
    public int structSize = 0;
    public String filter = null;
    public String file = null;
    // ...
} //OpenFileName

public class LibWrap
{
    // Declare a managed prototype for the unmanaged function.
    /** @attribute DllImport("Comdlg32.dll", CharSet = CharSet.Auto)
     */
    public static native boolean GetOpenFileName(
        /** @attribute In()
            @attribute Out()
         */
        OpenFileName ofn);
} //LibWrap
継承階層継承階層
System.Object
   System.Attribute
    System.Runtime.InteropServices.InAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
InAttribute メンバ
System.Runtime.InteropServices 名前空間
OutAttribute
StringBuilder
その他の技術情報
Blittable 型と非 Blittable 型



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「InAttribute クラス」の関連用語

InAttribute クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



InAttribute クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS