_FieldInfo.IsNotSerializedとは? わかりやすく解説

FieldInfo.IsNotSerialized プロパティ

このフィールドに、NotSerialized 属性設定されているかどうかを示す値を取得します

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

Dim instance As FieldInfo
Dim value As Boolean

value = instance.IsNotSerialized
public bool IsNotSerialized { get;
 }
public:
virtual property bool IsNotSerialized {
    bool get () sealed;
}
/** @property */
public final boolean get_IsNotSerialized ()

プロパティ
フィールドNotSerialized 属性設定されている場合trueそれ以外場合false

解説解説

IsNotSerialized プロパティは、フィールドFieldAttributes.NotSerialized フラグマークされている場合は、true返します。このフラグフィールド設定されている場合、型がリモートならばそのフィールドシリアル化する必要がないことを示します

使用例使用例

MyClass のフィールドフィールド情報取得しフィールドシリアル化できるかどうか判断しその結果表示する例を次に示します

Imports System
Imports System.Reflection
Imports System.Runtime.Serialization
Imports Microsoft.VisualBasic

<Serializable()> _
Public Class [MyClass]
    Public myShort As Short

    ' The following field will not be serialized.  
    <NonSerialized()> Public myInt As
 Integer
End Class '[MyClass]

Public Class Type_IsNotSerializable

    Public Shared Sub Main()
        ' Get the type of MyClass.
        Dim myType As Type = GetType([MyClass])

        ' Get the fields of MyClass.
        Dim myFields As FieldInfo() = myType.GetFields((BindingFlags.Public
 Or BindingFlags.NonPublic Or BindingFlags.Instance
 Or BindingFlags.Static))
        Console.WriteLine(ControlChars.Cr & "Displaying whether
 or not the field is serializable." & ControlChars.Cr)
        Console.WriteLine()
        ' Displaying whether or not the field is serializable.
        Dim i As Integer
        For i = 0 To myFields.Length - 1
            If myFields(i).IsNotSerialized Then
                Console.WriteLine("The {0} field is not serializable.",
 myFields(i))
            Else
                Console.WriteLine("The {0} field is serializable.",
 myFields(i))
            End If
        Next i
    End Sub 'Main
End Class 'Type_IsNotSerializable
using System;
using System.Reflection;
using System.Runtime.Serialization;

public class MyClass 
{
    public short myShort;

    // The following field will not be serialized.  
    [NonSerialized()]
    public int myInt;
}
public class Type_IsNotSerializable
{
    public static void Main()
    {  
        // Get the type of MyClass.
        Type myType = typeof(MyClass);
 
        // Get the fields of MyClass.
        FieldInfo[] myFields = myType.GetFields(BindingFlags.Public |
            BindingFlags.NonPublic |
            BindingFlags.Instance |
            BindingFlags.Static);
        Console.WriteLine("\nDisplaying whether or not the field is serializable.\n");
      
        // Display whether or not the field is serializable.
        for(int i = 0; i < myFields.Length;
 i++)
            if(myFields[i].IsNotSerialized)
                Console.WriteLine("The {0} field is not serializable."
,
 myFields[i]);
            else
                Console.WriteLine("The {0} field is not serializable."
,
 myFields[i]);
    }
}
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::Serialization;

public ref class MyClass
{
public:
   short myShort;

   // The following field will not be serialized.  

   [NonSerialized]
   int myInt;
};

int main()
{
   // Get the type of MyClass.
   Type^ myType = MyClass::typeid;

   // Get the fields of MyClass.
   array<FieldInfo^>^myFields = myType->GetFields( static_cast<BindingFlags>(BindingFlags::Public
 | BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::Static) );
   Console::WriteLine( "\nDisplaying whether or not the field is serializable.\n"
 );

   // Display whether or not the field is serializable.
   for ( int i = 0; i < myFields->Length;
 i++ )
      if ( myFields[ i ]->IsNotSerialized )
            Console::WriteLine( "The {0} field is not serializable.", myFields[
 i ] );
      else
            Console::WriteLine( "The {0} field is serializable.", myFields[
 i ] );
}
import System.*;
import System.Reflection.*;
import System.Runtime.Serialization.*;

public class MyClass
{
    public short myShort;
   
    // The following field will not be serialized.  
    /** @attribute NonSerialized()
     */
    public int myInt;
} //MyClass

public class TypeIsNotSerializable
{
    public static void main(String[]
 args)
    {
        // Get the type of MyClass.
        Type myType = MyClass.class.ToType();

        // Get the fields of MyClass.
        FieldInfo myFields[] = myType.GetFields(BindingFlags.Public 
            | BindingFlags.NonPublic | BindingFlags.Instance 
            | BindingFlags.Static);
        Console.WriteLine("\nDisplaying whether or not the " 
            + "field is serializable.\n");

        // Display whether or not the field is serializable.
        for (int i = 0; i < myFields.length;
 i++) {
            if (myFields[i].get_IsNotSerialized()) {
                Console.WriteLine("The {0} field is not serializable."
,
                    myFields.get_Item(i));
            }
            else {
                Console.WriteLine("The {0} field is not serializable."
,
                    myFields.get_Item(i));
            }
        }
    } //main 
} //TypeIsNotSerializable
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

_FieldInfo.IsNotSerialized プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

COM オブジェクトに、IsNotSerialized プロパティへのバージョン依存しないアクセス用意されています。

このプロパティは、CLS準拠していません。  

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

Dim instance As _FieldInfo
Dim value As Boolean

value = instance.IsNotSerialized
bool IsNotSerialized { get; }
property bool IsNotSerialized {
    bool get ();
}
/** @property */
boolean get_IsNotSerialized ()
function get IsNotSerialized () : boolean

プロパティ
フィールドNotSerialized 属性設定されている場合trueそれ以外場合false

解説解説

このプロパティは、アンマネージ コードからマネージ クラスアクセスするためのプロパティであるため、マネージ コードからは呼び出さないください

IsNotSerialized プロパティは、このフィールドNotSerialized 属性設定されているかどうかを示す値を取得します

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
_FieldInfo インターフェイス
_FieldInfo メンバ
System.Runtime.InteropServices 名前空間



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

辞書ショートカット

すべての辞書の索引

_FieldInfo.IsNotSerializedのお隣キーワード
検索ランキング

   

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



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

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

©2024 GRAS Group, Inc.RSS