FieldInfo.IsNotSerialized Propriété

Définition

Attention

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

Obtient une valeur indiquant si ce champ est doté de l'attribut NotSerialized.

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; }

Valeur de propriété

true si l'attribut NotSerialized du champ est défini ; sinon, false.

Implémente

Attributs

Exemples

L’exemple suivant obtient les informations de champ des champs de MyClass, détermine si les champs peuvent être sérialisés et affiche les résultats.

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

Remarques

La IsNotSerialized propriété retourne true lorsque le champ est marqué avec l’indicateur FieldAttributes.NotSerialized . Lorsque cet indicateur est défini sur un champ, il indique que le champ n’a pas besoin d’être sérialisé lorsque le type est distant.

S’applique à

Produit Versions (Obsolète)
.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

Voir aussi