Posts

Showing posts from March, 2017
Image
Extensions and Reflections and Generics oh my! Copyright - https://www.flickr.com/photos/dcwriterdawn/ Creating an extension class for View Models to save public properties using Generics and Delegates, replacing a reflection implementation. Introduction Recently I was working on an MVC project in which the client wanted to persist a form used to filter data to a data store so that the form could be recalled with any number of saved states. I chose to persist the data in a dictionary object which could be persisted in a Entity Attribute Value table.  I created two extension methods, one which saves model properties to a Dictionary and the other which applies data from a Dictionary and overwrites properties of the model.  The extension method for Getting the properties is called  GetModelValues  and the other method is  ValuesToModel . Both extensions are defined as a type of T where T is defined as an Interface. This is to ensure that by simply adding a interf