NET developers. Decided to make layer to extract some data from data source to build tables in some generated documents further.
Maybe question is simple, but I am confused a little bit.
The problem is - want to build table model which could contain string or image. At the moment I ended up with that set of classes, but I am not sure that is the proper way:
public class TableModel
{
public long RowsCount { get; set; }
public long ColumnsCount { get; set; }
public List<List<DataUnitModel>> Table { get; set; }
}
public class DataUnitModel
{
public object Element { get; set; }
public Type ElementType { get; set; }
}
It suppose to be working like that (pseudocode):
public void BuildTable(TableModel myTable)
{
for (var i = 0; i < myTable.Rows)
{
for (var j = 0; j < myTable.Cols)
{
DocumentCurrentRange.Insert(myTable.Table[i][j]);
}
}
}
UPD:
Data types - it could be jsut simple strings or jpg/png/bmp images
UPD2:
Txnks guys, realized that I dont need GetElement
function here its useless.
It appears you are taking a slightly wrong approach here, i.e. you are solving the wrong problem. Your "table" could simply be a
List<List<object>>
, and it would essentially carry the same information as your classes are carrying now (apart from the "number of columns", if the list is empty).If I understood your question, each element type will be "rendered" in some way (as a report, or in a webpage, or converted to something else). If that's true, I would concentrate on defining what's common for a rendering step of all the elements. So, the end result should allow you to write something like:
A simplified report model could be a list of paragraphs, tables, figures, something like:
Or perhaps each element will have a list of child elements too, but this is a simple example.
Your model would then be expressed with something like:
And then, independently, you might have a renderer interface like this:
Which then makes creating different renderers obvious:
And all you are left to do is create a mapping of renderers for each
IItem
type (item type -> renderer). This can even be done through reflection/dependency injection, so that everything will "just work" when you decide to create a new renderer type:And now we get to our desired usage:
This brings you to table items, which are interesting in your case, because they can apparently contain images and paragraphs as table cells. This means you could define them something like:
And then the renderer is again interesting because it's a composite (recursive) renderer:
Which means you need to pass the dictionary to the renderer constructor: