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