Example #1
0
        public void Load()
        {
            BeforeLoad();

            var type       = GetType();
            var fieldsInfo = mCore.GetCachedFields(type);

            for (int i = 0; i < fieldsInfo.CachedFields.Length; i++)
            {
                if (!typeof(ISaveableField).IsAssignableFrom(fieldsInfo.CachedFields[i].FieldInfo.FieldType))
                {
                    continue;
                }

                var key = GetKey(Key, fieldsInfo.CachedFields[i].FieldInfo.Name);
                if (Storage.HasKey(key))
                {
                    var saveableField = (ISaveableField)fieldsInfo.CachedFields[i].Getter(this);
                    var bridge        = new SaveableFieldsBridge(key, Storage);
                    var newValue      = saveableField.LoadValue(bridge);
                    fieldsInfo.CachedFields[i].Setter(this, newValue);
                }
            }

            AfterLoad();
        }
Example #2
0
        public void Save()
        {
            BeforeSave();

            var type       = GetType();
            var fieldsInfo = mCore.GetCachedFields(type);

            for (int i = 0; i < fieldsInfo.CachedFields.Length; i++)
            {
                if (!typeof(ISaveableField).IsAssignableFrom(fieldsInfo.CachedFields[i].FieldInfo.FieldType))
                {
                    continue;
                }

                var key           = GetKey(Key, fieldsInfo.CachedFields[i].FieldInfo.Name);
                var saveableField = (ISaveableField)fieldsInfo.CachedFields[i].Getter(this);
                var bridge        = new SaveableFieldsBridge(key, Storage);
                saveableField.SaveValue(bridge);
            }

            AfterSave();
        }