I'm currently working on a project that has several classes that needs to mapping into each other. The mapping is very basic, but I always lose a lot of time building something like this:
void ConvertA1ToA2(A1 arg1, A2 arg2)
{
A1.SomeField = A2.SomeOtherField;
//A lot more fields with basic conversions and naming slightly deferring
}
void ConvertA2ToA1(A2 arg1, A1 arg2)
{
A1.SomeOtherField = A2.SomeField;
//A lot more fields with basic conversions and naming slightly deferring
}
To avoid this, I was trying to build a tool which would receive a DLL path, would search classes with a custom attribute receiving a parameter with the class conversion name. After this I would search the attributes for another custom attribute searching for the correspondent field. After all this I would generate a .cs that I would include manually in the project, and so skipping a lot of time doing theses conversions.
I am currently loading successfully the DLL and search correctly the custom attributes so my only final step is to generate the .cs file. Is there any library that would help me with that? Or should I use the default StreamWriter API?
Aucun commentaire:
Enregistrer un commentaire