/// <summary> /// Creates a new instance /// </summary> protected MultiPeriodField(IDictionary <string, decimal> store = null) { if (store != null) { Store = store.Select(kvp => new PeriodField(PeriodAsByte.Convert(kvp.Key), kvp.Value)).ToArray(); } }
/// <summary> /// Gets the value of the field for the requested period /// </summary> /// <param name="period">The requested period</param> /// <returns>The value for the period</returns> public decimal GetPeriodValue(string period) { return(GetPeriodValue(PeriodAsByte.Convert(period))); }
/// <summary> /// Returns a string that represents the current object. /// </summary> /// <returns> /// A string that represents the current object. /// </returns> /// <filterpriority>2</filterpriority> public override string ToString() { return(StoreIsEmpty ? "" : string.Join(";", Store.Select(x => PeriodAsByte.Convert(x.Period) + ":" + x.Value))); }
/// <summary> /// Sets the value of the field for the specified period /// </summary> /// <param name="period">The period</param> /// <param name="value">The value to be set</param> public void SetPeriodValue(string period, decimal value) { SetPeriodValue(PeriodAsByte.Convert(period), value); }
/// <summary> /// Gets a dictionary of period names and values for the field /// </summary> /// <returns>The dictionary of period names and values</returns> public IReadOnlyDictionary <string, decimal> GetPeriodValues() { return(StoreIsEmpty ? new Dictionary <string, decimal>() : Store.ToDictionary(field => PeriodAsByte.Convert(field.Period), field => field.Value)); }
/// <summary> /// Gets the list of available period names for the field /// </summary> /// <returns>The list of periods</returns> public IEnumerable <string> GetPeriodNames() { return(StoreIsEmpty ? Enumerable.Empty <string>() : Store.Select(field => PeriodAsByte.Convert(field.Period))); }
/// <summary> /// Returns true if the field contains a value for the requested period /// </summary> /// <param name="period">The requested period</param> public bool HasPeriodValue(string period) => !StoreIsEmpty && Store.Any(field => field.Period == PeriodAsByte.Convert(period));