Evening all,
I’ve written a transfer application that needs to perform an update, then update a date corresponding to that update. I.e.
string content = string.Empty; IIvdManager manager; DateTime configDate; if (table == Tables.Asset) { content = WebService.GetTblAsset(companyId); manager = ivdData.Instance.Asset; configDate = ivdConfig.LAST_UPDATE_ASSET; } else if (table == Tables.Site) { content = WebService.GetTblSite(companyId); manager = ivdData.Instance.Site; configDate = ivdConfig.LAST_UPDATE_SITE; } else if (table...) { ... } if (content.Length > 0) { if (UpdateManager(manager, content)) { configDate = DateTime.Now; } }
What I want is for the configDate property to update the corresponding Date Get/Set in my ivdConfig Static Class.
How can I do this?
Have you considered the state pattern?
Subclass your table (the table variable) and add a virtual method (Update() perhaps?) that you then override in each specific table type. This will completely remove the else ifs as it will just become:
Pass down any objects you need to this call and then get the value back from the table (as it can update its own specific date property within its implementation of Update()).
I apologise if I have the wrong end of the stick but i’m not 100% sure what you are asking to be honest.