-
-
Save ilkerde/838709 to your computer and use it in GitHub Desktop.
using System; | |
namespace Is.This.A.Smell { | |
public static class EnumExtensions { | |
public static string AsString(this Enum e) { | |
return Enum.GetName(e.GetType(), e); | |
} | |
} | |
} |
So, the smell is not the extension method on an enum, but a string-based enum conversion (mapping) or a view. Agreed.
P.S. You need to try to write less. I consider long comments a smell ;)
@rseso: Very interesting approach. I'd never thought of decorating enum values with metadata.
@ilker: Man, that's what I call continuous improvement! ;)
Most definitively a smell. But not the extension method itself, but the need for it and the use of Enum in a first place. This seems to no longer be a simple Enum and should most likely be replaced by a proper class(-hierarchy). We found that using an enum is often a premature optimization that will bite you in the end. Especially when decorating enums with attributes ... think very hard before going down that road.
Why did you use an enum in this case?
Hi Ilker,
I would say if you use it for a map then it's a smell.
But consider https://gist.github.com/837312. You could use your method to replace the string "Abrufauftrag" with it and then you might get better refactoring support.
IMHO the method alone is no smell but within your context it is.
Regards, Steffen