I wanted to take some code and make it more general purpose
C# generics didn’t quite cut it.
I wanted a generic routine that could save objects with different properties
But I didn’t want ugly, “hard to comprehend in 3 months from now” code
The traditional approach is to use Interfaces to guarantee that templated objects support the same methods
But I wanted to make objects generic that had different properties (An impossibility as far as I could tell)
If you want to support objects that have different properties, I couldn’t find an elegant way to do it
The code speaks for itself so there is barely any narrative here
I present the before and after
I’m sure many of you will find a better way and I look forward to seeing the comments
There is use of delegates so that even a function call can be abstracted out of the code
Some of code can be found here for serialization
The code can serialize and save a collection of objects
The collection is composed of string paths to folders (I couldn’t save the StorageFolder object by itself)
This the "before" version.
It makes NO USE OF GENERICS
This the "after" version.
It makes USE OF GENERICS
Why does type T2 have to have those 2 properties.
foreach (T item in localData)
...or replace item.FolderName with
It's 2014... Stop using XML. > ToXml Just serialize it to JSON.