Saving class properties

I created a class with several properties, and its methods, I need to save the current properties values and be able to recover them later.
I know it is possible to save to binary file each property and then read then in order to repopulate the class.
This seems not very optimal when the class has more than 20 properties, and some are arrays, and… I’ve and array of this class of about 100 instances.
Is there a way to save a class like and structure?
Probably it is silly question.

@Enric Herrera — For extracting the data, you may want to use Introspection to determine the properties’ name and value.

For storing on disk, I would recommend using a Dictionary (composed only of basic types or array of them) and write it out as a PropertyList. It is way larger than a simple binary stream but it has other advantages (being almost human readable/editable, less error prone…). I can extract the module from MacOSLib if you want to.

Sorry I did not understand, probably I expressed my question in a wrong way.
Imagine a class StudentClass with first name, last name, etc.
To save the StudenClass instances should I create a SQLite database and pass all properties to the appropriate fields?, o pass each instance as a row to a CSV text file, it is not a better way?

Personally, I would use a SQLite database.

@Enric Herrera — Writing to a database or creating a CSV file will be tricky because you said that some properties are arrays. That is why I propose you to use a Dictionary which can store values (string, integer, double…) and even arrays, and it can be written to disk very easily.

For example, you would create an Array with a Dictionary for each student with all the properties you want. Then you can store this array into a Dictionary and save it to disk as a so-called “PropertyList” file. When reading this file back, the whole dictionary structure (and arrays) will be re-created. Then you can re-create each student object from its Dictionary.

Writing to a database will give you more capabilities (when working with multiple records), such as sorting, filtering, etc. Each StudentClass would be a single record in a database table called “Students”. The Student table will have fields for each property of your class. However, if some of the properties contain arrays, it might make sense to store these in a separate related table with a foreign key.

If you don’t want to use a database for some reason, then you can “serialize” your class to Json, which is just text, then store it on disk. Json is good for something like this. You will need to write a method called “Serialize” on your class that creates Json from all of the properites. Then you will need a way to “Deserialize” the json back to the class.

Following is an example that will magically serialize ANY class automatically: https://github.com/ktekinay/Data-Serialization

Thanks all, I will investigate all your suggestions, I did not used JSON neither Dictionary, I need a little reading about it.