I have a fairly large class A with a large number of participants, and I have a fairly large class B that can be created with object A. Object A can be created when object B. I need both, since A is a viewModel that has validation and B is a graphical description that can be easily constructed.
How to do this conversion?
here is an example to illustrate what i want to do:
class A { string s; string t; string u; string v; enum a; enum b; enum c; enum d; enum e; Dictionary<enum, string> dict; } class B { string someString;
Of course, it’s easy to do some mapping and create an object B, and it’s easy to write a simple map B => A by inverting the construction rule A => B
So the questions are:
- Are there any known patterns to achieve this?
- Is there a way to execute C # by default?
Writing something like this does not seem to fit, it ends with hundreds of lines of code.
I was thinking of some kind of converter classes for parts, e.g. SomeStringConverter, SomeValueConverter, ...
- How can I abstract the necessary members of A along with the rules for display.
- How can I write these rules to have the easiest way to execute A => B and B => A.
Edit: The sample here is referred to as "Best Practice" and not as "GoF Design Templates"
SomeString in class B is a kind of "selector", it selects a drawing of options, it is always 25 characters, and enumerations in class A select these characters, but not more often than 1 on 1.
Let's say for example: Aa = "Filled", Ab = "SingleCoordinate", Ac = "DrawHints" will lead to something like SomeString =
"Y**D***RR****---***---***"
i.e. the combination is important to get such a string, but from the combination you can get the enumerations that must be set in object A.
Edit2:
I am particularly interested in ways to use my matching rules for both ways, i.e. Aa = "Filled" in combination with Ab = "SingleCoordinate" associated with Ac = "DrawHints" will result in (partial string) "Y**D***RR"
, and this partial string also means that Aa must be set to "Filled", etc.