public static int GetMaxVersion(IEnumerable <FieldInfo> fields) { int version = -1; foreach (var f in fields) { PersistencyHelper.GetPersistentFieldInfo(f, out PersistentFieldAttribute info); if (info.AvalailableSince > version) { version = info.AvalailableSince; } } return(version); }
public static IEnumerable <string> RestorePersistentFields(object obj, SerializationInfo info, IEnumerable <FieldInfo> fields, int version) { List <string> persistentNames = new List <string>(); foreach (var f in fields) { // the version is restored at this point if (PersistencyHelper.GetPersistentFieldInfo(f, out PersistentFieldAttribute fieldInfo)) { if (fieldInfo.AvalailableSince <= version) { var val = info.GetValue(fieldInfo.Name, f.FieldType); f.SetValue(obj, val); persistentNames.Add(fieldInfo.Name); } else { Assert.True(fieldInfo.HasDefault, "The field {0} cannot be restored from the current stream", fieldInfo.Name); } } } return(persistentNames); }