Thank god the else part is not the same!
-
Fortunately there were three cases alone, other wise he would have ended up parsing the same enum multiple times! Comments are mine, rest remains the same!
foreach (string name in names) { if (StringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value)) { return Enum.Parse(enumType, name); // <------ } else if (AlternateStringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value)) { return Enum.Parse(enumType, name); // <------ } else if (name.Equals(value)) { return Enum.Parse(enumType, name); // // <------ } }
Regards Vallarasu S | FSharpMe.blogspot.com
-
Fortunately there were three cases alone, other wise he would have ended up parsing the same enum multiple times! Comments are mine, rest remains the same!
foreach (string name in names) { if (StringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value)) { return Enum.Parse(enumType, name); // <------ } else if (AlternateStringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value)) { return Enum.Parse(enumType, name); // <------ } else if (name.Equals(value)) { return Enum.Parse(enumType, name); // // <------ } }
Regards Vallarasu S | FSharpMe.blogspot.com
:doh:
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking
-
Fortunately there were three cases alone, other wise he would have ended up parsing the same enum multiple times! Comments are mine, rest remains the same!
foreach (string name in names) { if (StringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value)) { return Enum.Parse(enumType, name); // <------ } else if (AlternateStringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value)) { return Enum.Parse(enumType, name); // <------ } else if (name.Equals(value)) { return Enum.Parse(enumType, name); // // <------ } }
Regards Vallarasu S | FSharpMe.blogspot.com
He made his solution future-proof: somewhen in the future, Enum.Parse might return different results depending on the cases he described here. Be prepared!
-
Fortunately there were three cases alone, other wise he would have ended up parsing the same enum multiple times! Comments are mine, rest remains the same!
foreach (string name in names) { if (StringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value)) { return Enum.Parse(enumType, name); // <------ } else if (AlternateStringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value)) { return Enum.Parse(enumType, name); // <------ } else if (name.Equals(value)) { return Enum.Parse(enumType, name); // // <------ } }
Regards Vallarasu S | FSharpMe.blogspot.com
-
Fortunately there were three cases alone, other wise he would have ended up parsing the same enum multiple times! Comments are mine, rest remains the same!
foreach (string name in names) { if (StringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value)) { return Enum.Parse(enumType, name); // <------ } else if (AlternateStringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value)) { return Enum.Parse(enumType, name); // <------ } else if (name.Equals(value)) { return Enum.Parse(enumType, name); // // <------ } }
Regards Vallarasu S | FSharpMe.blogspot.com
Because sometimes it's not enough to evaluate it once. I suppose, for good measure, he could have put an
Enum val = (Enum)Enum.Parse(enumType, name);
immediately after thefor
.*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier