sapiens / SqlFu

Fast and versatile .net core data mapper/micro-orm
Other
229 stars 50 forks source link

Allows custom object properties to use a converter if one is registered. #17

Closed ventaur closed 11 years ago

ventaur commented 11 years ago

PR to implement request for issue: https://github.com/sapiens/SqlFu/issues/16

I couldn't get the tests to run due to the missing SQLite DB, but I do have this exact code working in production for a month or so now.

Here are 2 examples for registering converters for properties of a custom object type. Properties of these types on my models map to a string ("ME", "OA", etc.) and a char ('I', 'S', etc.) respectively. In this case, these types descend from the Enumeration class found here: https://github.com/HeadspringLabs/Enumeration/

PocoFactory.RegisterConverterFor(o => QuizAnswerType.FromValue(o.ToString()));
PocoFactory.RegisterConverterFor(o => QuizFeedbackType.FromValue(o.ToString()[0]));

public class QuizAnswerType : Enumeration<QuizAnswerType, string> { ... }
public class QuizFeedbackType : Enumeration<QuizFeedbackType, char> { ... }

The above classes for properties on my models, with the code in this PR, have been working in a production website for over a month now. I hope this is helpful to others.

sapiens commented 11 years ago

This has been merged with Devel branch