New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for immutable types #84
Comments
Do you have an API in mind, so I can get an idea? Then we could see, what’s possible and eventually make a new major release and changes to the existing API. 🙂 |
The only requirement for an API is that the mapping class (it must be custom) would have to call the constructor explicitly. If you use reflection, there is a complicated way to do that, but I think the simplest API would be one that allows the mapping class to extract the column values, then call the constructor, and return the instance to your infrastructure. You already have a way to extract column values (strong typing there would be bonus). |
Currently the CsvMapping class requires a parameter less constructor. |
You could make an equivalent to CsvMapping specifically for immutable types. |
If you want to simply extend the MapUsing API, you could have a delegate parameter that does not take the instantiated object as input, only the values. Then a null return value means failure, or if you allow value types to be constructed, a Result structure is returned, and your base class (CsvImmutableMapping) would need to have a MapUsing method that accepts the correct delegate type (i.e., the delegate is strongly typed by its output). |
Sounds good! I think using |
I had a try at this, and I believe both MapUsing and a similar syntax to the existing MapProperty methods can be interesting. |
A great PR! Please give me some time to take a look at it. :) |
I realize this is out of scope in the original design, but do you have any plans to add support for a custom mapping to an immutable type? Specifically, to map to a class that has read-only properties, with the property values passed in the constructor. This means the mapping must create the instance. Thank you.
The text was updated successfully, but these errors were encountered: