Alternative to pr/251. That method uses an enum with a function to tr… #258
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…anslate the names. My implementation names the enum values the actual API string values which eliminates the need for the extra ConversationTypesToQueryParam() function.
For example, instead of:
Tuple.Create("types", Conversation.ConversationTypesToQueryParam(types));
We can leave this unchanged:
parameters.Add(Tuple.Create("types", string.Join(",", types)));
This works because when string.Join translate types[] into strings, it calls ToString() which by default returns the enum element name.
This is also nice because we don't have to update the ConversationTypesToQueryParam() function whenever elements are added or removed from the enum.
If there is some kind of naming standard violation here, (e.g. The first enum element should be PublicChannel instead of public_channel), yet another alternative would be to use a class instead of an enum. For example:
public static class Type {
public static readonly string PublicChannel = "public_channel";
public static readonly string PrivateChannel = "private_channel";
...
}
There is a detailed discussion on using friendly strings with enums on Stack Overflow here:
https://stackoverflow.com/questions/479410/enum-tostring-with-user-friendly-strings