Freigeben über


FieldInfo.IsNotSerialized-Eigenschaft

Ruft einen Wert ab, der angibt, ob dieses Feld über das NotSerialized-Attribut verfügt.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public ReadOnly Property IsNotSerialized As Boolean
'Usage
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 ()
public final function get IsNotSerialized () : boolean

Eigenschaftenwert

true, wenn für das Feld das NotSerialized-Attribut festgelegt ist, andernfalls false.

Hinweise

Die IsNotSerialized-Eigenschaft gibt true zurück, wenn das Feld mit dem FieldAttributes.NotSerialized-Flag gekennzeichnet ist. Durch Festlegen dieses Flags für ein Feld wird angegeben, dass das Feld nicht serialisiert werden muss, wenn der Typ remote verwendet wird.

Beispiel

Im folgenden Beispiel werden die Feldinformationen der Felder von MyClass abgerufen. Außerdem wird bestimmt, ob die Felder serialisiert werden können, und die Ergebnisse werden angezeigt.

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

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

FieldInfo-Klasse
FieldInfo-Member
System.Reflection-Namespace
FieldAttributes-Enumeration