Skip to content

Instantly share code, notes, and snippets.

@ilkerde
Created February 22, 2011 14:08
Show Gist options
  • Save ilkerde/838709 to your computer and use it in GitHub Desktop.
Save ilkerde/838709 to your computer and use it in GitHub Desktop.
I wonder whether introducing such an extension is considered a smell. For me it's most likely a smell.
using System;
namespace Is.This.A.Smell {
public static class EnumExtensions {
public static string AsString(this Enum e) {
return Enum.GetName(e.GetType(), e);
}
}
}
@shishkin
Copy link

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 ;)

@ilkerde
Copy link
Author

ilkerde commented Feb 22, 2011

@forki: granted, makes life easier and hence is a good thing.
@shishkin: thanks. <- better? ;-)

@ilkerde
Copy link
Author

ilkerde commented Feb 22, 2011

@rseso: Very interesting approach. I'd never thought of decorating enum values with metadata.

@shishkin
Copy link

@ilker: Man, that's what I call continuous improvement! ;)

@dun3
Copy link

dun3 commented Feb 23, 2011

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment