WKFramework is a small framework written in C#. For now only settings, navigation and some utils are available.
Settings
Key-value settings, where any object can be used as a key or value. For now there are two classes available, one to store settings in a file and another to store them in database:
- FileSettings
- MsSqlServerSettings
Both classes are configurable (you can pass your own serializer, set data type in database etc.). You can also easily attach MsSqlServerSettings to any existing database or create a new one using this class.
Writing to settings:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
var person = new Person() { FirstName = "John", LastName = "Smith" }; //the same interface is availalbe for MsSqlServerSettings var settings = FileSettings("settings.dat"); settings.WriteProperties(person); //saves only public properties settings.WriteStaticProperties(typeof(Settings)); settings.WriteValue("LastUpdate", DateTime.Now); settings.WriteValue(SettingsKey.Counter, 20); |
Reading from settings:
1 2 3 4 5 6 7 |
var person = new Person(); var settings = FileSettings("settings.dat"); settings.ReadProperties(person); settings.ReadStaticProperties(typeof(Settings)); var lastUpdate = settings.ReadValue<DateTime>("LastUpdate"); var counter = settings.ReadValue<int>(SettingsKey.Counter); |
You can mark properties with [NonSerializedProperty] to avoid serializing them while using WriteProperties or WriteStaticProperties.
Navigation (for WPF)
Simple service to help with navigation in ViewModel-First approach. It provides a fluent interface to show and setup windows. They are automatically localized using reflection, so the only thing you need to do is to stick to the naming convention: NameViewModel and NameView.
Example:
1 2 3 4 5 |
new NavigationService() .GetWindow<PersonDetailsViewModel>() .WithParam(vm => vm.Person, personToShow) .DoIfAccepted(vm => RefreshList()) .ShowDialog(); |
Utils
For now there are only two serializers: BinarySerializer and GZipSerializer. Both can be used with Settings. There is also an extension which performs a deep copy of an object (but it has to be marked as [Serializable]).