public List <GameProperty> GetProperties(string id) { return (GetType() .GetProperties() .Where(x => x.GetCustomAttribute <GamePropertyAttribute>()?.Id == id) .Select(x => GameProperty.Create(x.GetCustomAttribute <GamePropertyAttribute>()?.Id, x.GetValue(this), true)) .ToList()); }
public T ValueOf <T>(string id) { GameProperty property = GetProperty(id); if (property.ValueType?.IsEquivalentTo(typeof(T)) ?? false) { return((T)property.Value); } throw new Exception($"The specified property '{id}' does not match the implicit type reference of {typeof(T).Name}"); }
public T ValueOf <T>(string id) { GameProperty property = GetProperty(id); if (property.ValueType == null || !property.ValueType.IsEquivalentTo(typeof(T))) { throw new Exception("The specified type within the property does not match the implicit type reference"); } return((T)property.Value); }
public void AddToValue(string id, int value) { GameProperty property = GetProperty(id); if (property.ValueType != typeof(int)) { throw new Exception($"Cannot add to the specified property '{id}' as it is not a type of Int32"); } property.Value = (int)property.Value + value; }
public void AddToValue(string id, int value) { Console.WriteLine($"[{Format.Time(DateTime.UtcNow)}] Adding {value} to property {id}"); if (Properties.All(x => x.Id != id)) { throw new Exception($"Could not find the specified property '{id}'"); } GameProperty property = Properties.First(x => x.Id == id); if (property.ValueType != typeof(int)) { throw new Exception($"Cannot add to attribute '{id}' as it is not a type of Int32"); } property.Value = (int)property.Value + value; }