public virtual int GetVersion() { if (_version < 0) { _version = PersistencyHelper.GetMaxVersion(PersistentFields); } return(_version); }
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); }
public void GetObjectData(SerializationInfo info, StreamingContext context) { PrepareFieldBackup(); PersistencyHelper.BackupPersistentFields(this, info, PersistentFields); }
protected StructuredAttribute(SerializationInfo info, StreamingContext context) { PersistencyHelper.RestorePersistentFields(this, info, PersistentFields, GetVersion()); FieldDataRestored(); }