-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProfileEntry.cs
37 lines (33 loc) · 1.07 KB
/
ProfileEntry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
namespace bagpipe {
class ProfileEntry {
public OnlineProfilePropertyOwner Owner;
public int ID;
public SettingsDataType Type;
private object _value;
public object Value {
get => _value;
set {
if (IsValidValue(value)) {
_value = value;
} else {
string typeName = value?.GetType()?.Name ?? "null";
throw new ArgumentException($"Tried to set invalid type {typeName} for type field {Type}");
}
}
}
public OnlineDataAdvertisementType AdvertisementType;
public bool IsValidValue(object value) => Type switch {
SettingsDataType.Empty => value is null,
SettingsDataType.Int32 => value is int,
SettingsDataType.Int64 => value is long,
SettingsDataType.Double => value is double,
SettingsDataType.String => value is string,
SettingsDataType.Float => value is float,
SettingsDataType.Blob => value is byte[],
SettingsDataType.DateTime => value is DateTime,
SettingsDataType.Byte => value is byte,
_ => false,
};
}
}