Find the type of a Key and get all keys for certain type

Discussion and help for Easy Save 3
Post Reply
dearamy
Posts: 1
Joined: Tue Mar 27, 2018 8:25 am

Find the type of a Key and get all keys for certain type

Post by dearamy »

Hi ES3,

Is there any way to get the type of a certain key?
What if I forgot the key's type?

I mean does ES3 save the type info in its data?
I was thinking maybe something like this:

Code: Select all

Type ES3.GetType(string key)
And if there is type info in the data. Then maybe there's a generic way to find all the keys of a certain type:

Code: Select all

public static string[] GetKeys<T>(string filePath, ES3Settings settings)
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Find the type of a Key

Post by Joel »

Hi there,

There's currently no method for this, but this could be achieved as follows:
public Type ES3GetType(string key)
{
	using(var reader = ES3Reader.Create())
	{
		if(!Goto(key))
			throw new KeyNotFoundException("Key \"" + key + "\" was not found in file \""+settings.FullPath+"\". Use Load<T>(key, defaultValue) if you want to return a default value if the key does not exist.");

		return ReadTypeFromHeader<object>();
	}
}
With regards to finding all keys of a certain type, this would be less trivial. As we've not had a request for this before (in Easy Save 2 or Easy Save 3) we would need more interest to warrant implementing this feature.

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