static List<FieldInfo> GetSerializableFields(Type type)
{
List<FieldInfo> fields = new List<FieldInfo>();
for (Type baseType = type; baseType != null; baseType = baseType.BaseType) {
FieldInfo[] declFields = baseType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
Array.Sort(declFields, (a,b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));
fields.AddRange(declFields);
}
fields.RemoveAll(f => f.IsNotSerialized);
return fields;
}