FieldInfo.IsNotSerialized Właściwość

Definicja

Przestroga

Formatter-based serialization is obsolete and should not be used.

Pobiera wartość wskazującą NotSerialized , czy to pole ma atrybut.

C#
public bool IsNotSerialized { get; }
C#
[System.Obsolete("Formatter-based serialization is obsolete and should not be used.", DiagnosticId="SYSLIB0050", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public bool IsNotSerialized { get; }

Wartość właściwości

true jeśli pole ma NotSerialized ustawiony atrybut; falsew przeciwnym razie .

Implementuje

Atrybuty

Przykłady

Poniższy przykład pobiera informacje o polu pól w usłudze MyClass, określa, czy pola mogą być serializowane, i wyświetla wyniki.

C#
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]);
    }
}

Uwagi

Właściwość IsNotSerialized zwraca wartość true , gdy pole jest oznaczone flagą FieldAttributes.NotSerialized . Gdy ta flaga jest ustawiona na polu, wskazuje, że pole nie musi być serializowane, gdy typ jest zdalny.

Dotyczy

Produkt Wersje (Przestarzałe)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 (8, 9)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Zobacz też