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