Genghis is a set of extensions built on top of .NET and integrated with WinForms to provide application-level services in the same flavor as the Microsoft as the Microsoft Foundation Classes. This project seems a bit dead, and a bit buggy. However its a great repository of wisdom, since some cool people work or have worked on it.
Starting off with WindowSerializer, this is a cool way of doing a .NET component. When you drop it on your form, it will plug into its OnClose, OnLoad, OnResize and OnMove events, as well as nick itself the form instance variable.
When the form fires any of these events, the WindowSerializer will record the change, and when OnClose is fired, it will flush its state to disk. When OnLoad is fired, it would load that state and update the form’s properties as needed.
They tried to provide some sort of Strategy/Provider pattern, so you can choose what kind of storage you use for the form settings, defaulting to Isolated Storage
. I found some of the code they used there confusing. Some variables were not used at all, I think they were some ‘just in case’ code. Specifically I’m referring to the path idiom they used.
private string ValidatePath(string path, string argumentName)
Here, argumentName was never used in the function body. Also, path, which is seen here and previously being passed to the ctor, moved around in 4 places in the code, isn’t actually used for anything, which render this method and perhaps other path-handling methods useless.
What I would do, is provide an abstract class like they did, but leave all those path or logical setting separation out:
- Instantiate with the FQN for the form name
- The abstract class will contain the get/set property convenient methods, abstract “‘main” get/set methods and abstract Serialize/Deserialize methods
- The implementing object is a data object.
- Which could use .Net serialization, to Isolated Storage, if we decide to use XML. Or our own if we implement a registry based serialization