Following is a chunk of code from my class which generates PDF documents. I am refactoring my code and in the process I have created short methods. But I have to pass 'table i.e PdfPTable' to my methods again and again. How can I avoid this?
PdfPTable orgTable = new PdfPTable(2);
PdfPCell cell = null;
string orgName = dr["OrganizationName"].ToString();
cell = new PdfPCell(new Phrase(orgName, Heading1)) {Colspan = 2, BackgroundColor = BckColor, HorizontalAlignment = Element.ALIGN_CENTER };
orgTable.AddCell(cell);
AddOrganizationProfile(document, dr, orgTable);
OrganizationHeadOffice(document, dr, orgTable);
OrganizationContacts(document, orgTable, orgId);
private void OrganizationHeadOffice(Document document, DataRow dr, PdfPTable table)
{
AddTitle("Office Contact & Information:", table);
// How to avoid passing table variable again and again here.
AddLegend("Address:", table);
AddDataValue(dr["address"].ToString(), table);
AddLegend("Contact Number:", table);
AddDataValue(phone1, table);
}
private void AddTitle(string title, PdfPTable table)
{
table.AddCell(new PdfPCell(new Phrase(title, TableFontCaption)) { Colspan = 2, BackgroundColor = BckColor });
}
private void AddLegend(string legend, PdfPTable table)
{
table.AddCell(new PdfPCell() { Border = Rectangle.NO_BORDER, Phrase = new Phrase(legend, TableFontCaption) });
}
private void AddDataValue(string dataValue, PdfPTable table)
{
table.AddCell(new PdfPCell() { Border = Rectangle.NO_BORDER, Phrase = new Phrase(dataValue, TableFont) });
}