Use COUNT member in enums
This commit is contained in:
parent
e81a47d83f
commit
c8f2dbaadc
@ -7,7 +7,9 @@ namespace StudySystemClient {
|
||||
|
||||
public enum ActivityType {
|
||||
READING = 0,
|
||||
EXERCISES = 1;
|
||||
EXERCISES = 1,
|
||||
|
||||
COUNT;
|
||||
|
||||
public string to_string() {
|
||||
switch (this) {
|
||||
|
@ -67,7 +67,9 @@ namespace StudySystemClient.Response {
|
||||
public enum Value {
|
||||
INVALID_REQUEST = 0,
|
||||
INVALID_ARGUMENTS = 1,
|
||||
SERVER_ERROR = 2;
|
||||
SERVER_ERROR = 2,
|
||||
|
||||
COUNT;
|
||||
|
||||
public string to_string() {
|
||||
switch (this) {
|
||||
@ -91,9 +93,9 @@ namespace StudySystemClient.Response {
|
||||
throw new DecodeError.INVALID_BODY(
|
||||
"Error was not an ENUMERATED");
|
||||
}
|
||||
if (enumerated.value < 0 || enumerated.value > 2) {
|
||||
if (enumerated.value < 0 || enumerated.value >= Value.COUNT) {
|
||||
throw new DecodeError.INVALID_BODY(
|
||||
"Error type was not in range 0..2");
|
||||
"Error type was not in range 0..$(Value.COUNT)");
|
||||
}
|
||||
value = (Value)enumerated.value;
|
||||
}
|
||||
@ -162,7 +164,7 @@ namespace StudySystemClient.Response {
|
||||
string name, Der.Datum datum) throws DecodeError {
|
||||
if (datum is Der.Enumerated) {
|
||||
var value = datum.value;
|
||||
if (0 <= value <= 1)
|
||||
if (0 <= value < ActivityType.COUNT)
|
||||
return (ActivityType)value;
|
||||
throw new DecodeError.INVALID_BODY(
|
||||
"Invalid value for ActivityType: %lld", value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user