FieldInfo.IsNotSerialized 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 필드에 NotSerialized 특성이 있는지 여부를 나타내는 값을 가져옵니다.
public:
property bool IsNotSerialized { bool get(); };
public bool IsNotSerialized { get; }
member this.IsNotSerialized : bool
Public ReadOnly Property IsNotSerialized As Boolean
속성 값
true 필드에 특성 집합이 있으면 .이 NotSerialized 고, false그렇지 않으면 .입니다.
구현
예제
다음 예제에서는 MyClass 필드의 필드 정보를 가져오고, 필드를 serialize할 수 있는지 확인하고, 결과를 표시합니다.
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]);
}
}
Imports System.Reflection
Imports System.Runtime.Serialization
<Serializable()> _
Public Class [MyClass]
Public myShort As Short
' The following field will not be serialized.
<NonSerialized()> Public myInt As Integer
End Class
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
End Class
설명
IsNotSerialized 필드가 플래그로 표시되면 속성이 FieldAttributes.NotSerialized 반환 true 됩니다. 이 플래그가 필드에 설정되면 형식이 원격일 때 필드를 serialize할 필요가 없음을 나타냅니다.