private static FieldInfo[] GetSerializableFields(Type type)
{
if (type.IsInterface)
{
return Array.Empty<FieldInfo>();
}
if (!type.IsSerializable)
{
throw new SerializationException(SR.Format(SR.Serialization_NonSerType, type.FullName, type.Assembly.FullName));
}
var results = new List<FieldInfo>();
for (Type t = type; t != typeof(object); t = t.BaseType)
{
foreach (FieldInfo field in t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
{
if ((field.Attributes & FieldAttributes.NotSerialized) != FieldAttributes.NotSerialized)
{
results.Add(field);
}
}
}
return results.ToArray();
}