1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
private static bool SetFolderBasedOnFirstStatus(PurchaseOrder po) { bool documentFinished = false; if (po.FirstStatus == FIRSTSTATUS.Complete) { po.Folder = DOCUMENTFOLDER.History; documentFinished = true; } else if (po.FirstStatus == FIRSTSTATUS.Partial) po.Folder = DOCUMENTFOLDER.InProgress; else { po.Folder = DOCUMENTFOLDER.Inbox; } return documentFinished; } private static bool SetFolderBasedOnSecondStatus(PurchaseOrder po) { bool documentFinished = false; if (po.SecondStatus == SECONDSTATUS.Complete) { po.Folder = DOCUMENTFOLDER.History; documentFinished = true; } else if (po.SecondStatus == SECONDSTATUS.Partial) { po.Folder = DOCUMENTFOLDER.InProgress; } return documentFinished; }
Refactorings
No refactoring yet !
Ants
January 25, 2010, January 25, 2010 04:11, permalink
Give this a try...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
static bool SetFolderBasedOnStatus<T>(PurchaseOrder po, T value, T completeValue, T partialValue) where T : IComparable { if (value.CompareTo(completeValue) == 0) po.Folder = DOCUMENTFOLDER.History; else if (value.CompareTo(partialValue) == 0) po.Folder = DOCUMENTFOLDER.InProgress; return po.Folder == DOCUMENTFOLDER.History; } private static bool SetFolderBasedOnFirstStatus(PurchaseOrder po) { po.Folder = DOCUMENTFOLDER.Inbox; return SetFolderBasedOnStatus(po, po.FirstStatus, FIRSTSTATUS.Complete, FIRSTSTATUS.Partial); } private static bool SetFolderBasedOnSecondStatus(PurchaseOrder po) { return SetFolderBasedOnStatus(po, po.SecondStatus, SECONDSTATUS.Complete, SECONDSTATUS.Partial); }
I have these two very similar methods. Both do the same thing, but one is based off the enum FIRSTSTATUS and the other is based off SECONDSTATUS. I'd like to cut this down to one method, but I'm not sure the best way.