Loading/saving for unknown types at compile-time

Discussion and help for Easy Save 3
Post Reply
Gladyon
Posts: 30
Joined: Thu Sep 07, 2017 6:51 am

Loading/saving for unknown types at compile-time

Post by Gladyon »

Currently, ES3 load and save methods needs a type known at compile-time.
But sometime, we do not know the type at compile time, usually when reflection is used.
For example, if I define an interface 'IGameSettings', and then I use reflection in order to get all the struct that implement that interface, I get several different types that I'd like to save/load using ES3.
That can be useful if I want to take care myself of saving/loading settings for modders for example, all they would have to do is to create a struct that inherit from 'IGameSettings'.


I think it can be achieved using something like that (in addition to the existing methods):
public System.Object Load(string key, System.Object defaultValue, Type T)

public void Save(string key, System.Object value, Type T)
Obviously some casting would be necessary, but when we use reflection it's usually not a problem, and that way, it would be possible to load and save data without knowing the type at compile time, while still having all the typing features of ES3.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Loading/saving for unknown types at compile-time

Post by Joel »

Hi there,

We've not had these methods requested before, but generally if you're reliant on reflection you would also use reflection to call the generic method.

Alternatively I believe ES3.Load<System.Object> should also work.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply