While reading the following blog post(http://piotrgankiewicz.com/2017/01/09/async-http-api-and-service-bus/) I noticed this code snippet:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class States | |
{ | |
public static string Accepted => "accepted"; | |
public static string Processing => "processing"; | |
public static string Completed => "completed"; | |
public static string Rejected => "rejected"; | |
} |
This code is taking advantage of the Expression-bodied function members in C# 6. And although this is just a static class with some readonly properties I found it aesthecially pleasing and it looks like a useful (and more flexible) alternative to enums.
If you look at the syntax you had to use before, it just feels more like a normal class instead of an enum construct…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class States | |
{ | |
public static string Accepted | |
{ | |
get { return "accepted";} | |
} | |
public static string Completed | |
{ | |
get { return "completed";} | |
} | |
public static string Processing | |
{ | |
get { return "processing";} | |
} | |
public static string Rejected | |
{ | |
get { return "rejected";} | |
} | |
} |
An alternative approach would be using Getter-only auto-properties but it doesn’t feel the same as well…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class States | |
{ | |
public static string Accepted{get;} = "accepted"; | |
public static string Processing{get;} = "processing"; | |
public static string Completed{get;} = "completed"; | |
public static string Rejected{get;} = "rejected"; | |
} |