Skip to content

Conversation

@apresence
Copy link
Contributor

…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

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant