Is this considered a Generic collection?
-
Method/proc names anonymized, of course. C#.
private string GetProcNameFromMethod(string method) { string proc = string.Empty; switch (method) { case "Method1": proc = "Proc1"; break; case "Method2": proc = "Proc2"; break; case "Method3": proc = "Proc3"; break; case "Method4": proc = "Proc4"; break; case "Method5": proc = "Proc5"; break; case "Method6": proc = "Proc6"; break; case "Method7": proc = "Proc7"; break; case "Method8": proc = "Proc8"; break; case "Method9": proc = "Proc9"; break; case "Method10": proc = "Proc10"; break; case "Method11": proc = "Proc11"; break; case "Method12": proc = "Proc12"; break; case "Method13": proc = "Proc13"; break; case "Method14": proc = "Proc14"; break; } return proc; }
-
I'm curious where that was called from. I'm imagining a method that grabs a stack trace, looks one frame up, gets the method name then calls this.
-
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public object ProcPassThru(object o) { // stuff Dictionary<string, object> dic = (Dictionary<string, object>)o; string ProcName = GetProcNameFromMethod(dic["Method"].ToString()); // moar stuff }
-
So, someone created a service that accepts anything as a parameter and does one of an arbitrary number of things based on what is passed in. I believe we have found TRWTF.
-
Heh, yeah, ProcPassThru's the WTF; your first example's just a sort of jump table.
-
I thought that it was overly verbose.
Dictionary<string, string> MethodToProcMapping = new Dictionary<string,string>() { // stuff }; string procName = MethodToProcMapping.ContainsKey(method) ? MethodToProcMapping[method] : string.Empty;
-
Well, true. I didn't want to make any assumptions, in case of anonymization or me not knowing enough about reflection or whatever.
-
Well, true. I didn't want to make any buttumptions, in case of anonymization or me not knowing enough about reflection or whatever.
TDWTFTFY
-
FrostCat said:
Well, true. I didn't want to make any assumptions, in case of anonymization or me not knowing enough about reflection or whatever.TDWTFTFY
Frosty don't do dat.
-
Yeah, it's not exactly a WTF in its mechanics, it's just that it was about 40 lines longer than it needed to be (included references not shown in the OP that I removed).
-
Yeah, it's not exactly a WTF in its mechanics, it's just that it was about 40 lines longer than it needed to be (included references not shown in the OP that I removed).
Hah, yeah. I found something like that in our own codebase yesterday. I think it happened because it grew organically and nobody ever said "let's refactor this." I'm gonna do that tomorrow--I should be able to squeeze at least a hundred lines out of a 300-line routine.
-
Yeah, this class started out as 310 lines, I'm down to 255.