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