FieldInfo.IsNotSerialized Propiedad

Definición

Precaución

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

Obtiene un valor que indica si este campo dispone del atributo 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; }

Valor de propiedad

Es true si el campo tiene establecido el atributo NotSerialized; en caso contrario, es false.

Implementaciones

Atributos

Ejemplos

En el ejemplo siguiente se obtiene la información de campo de los campos de MyClass, se determina si se pueden serializar los campos y se muestran los resultados.

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

Comentarios

La IsNotSerialized propiedad devuelve true cuando el campo está marcado con la FieldAttributes.NotSerialized marca . Cuando esta marca se establece en un campo, indica que el campo no tiene que serializarse cuando el tipo está remoto.

Se aplica a

Produto Versións (Obsoleto)
.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

Consulte también