I’m trying to implement a report that is based on a web page. The web page is in one project MyProject.Web, and the report is in MyProject.Reports project. In both cases I want to display the same control element (a third-party chart control). The Reports project uses a slightly different implementation (meaning most all the members are compatible) of the third-party chart control. Almost all of the code can be copy-pasted between the two projects. However, the following code is not compatible in the Reports project:
chart.BorderOptions.Visible = false; // BorderOptions is not a member
needs to be replaced with:
chart.Borders = BorderSide.None;
This:
chart.Height = Unit.Pixel(300); // Unit type
chart.Width = Unit.Pixel(700); // Unit type
needs to be replaced with:
chart.Height = 300; // int type
chart.Width = 700; // int type
and finally:
chart.Padding.All = 0;
needs to be removed.
What’s best solution here?
Looks like a classic case of the adapter pattern.
Basically, you can encapsulate the pieces that are different and only implement them differently. You could either create a
MyAwesomeChartclass and subclass that or something more likeMyAwesomeChartSetter.