/// <summary> /// Assign: assign a new value to this instance /// </summary> /// <param name="value">The new value</param> /// <exception cref="ArgumentOutOfRangeException">Scales of this and the other must be (syntactical) equivalents</exception> /// <remarks>It is not possible to override operator=()</remarks> protected void Assign(ScaledType other) { if (Scale != other.Scale) { var msg = $"Assign: not supported: ({Scale})Value = ({other.Scale}){other.GetValue()}"; #if USE_LOG4NET log.Debug(msg); #endif throw new ArgumentOutOfRangeException(msg); } }
/// <summary> /// SetValue: change to value from another ScaledType, no scaling used. /// </summary> /// <param name="value">ScaledType child from which the value should be used.</param> /// <returns>True if the value is accepted by the child.</returns> public override bool SetValue(ScaledType value) { if (ReferenceEquals(this, value)) { return(true); } try { Value = (value is LongST) ? (value as LongST).value : (long)value.GetValue(); return(true); } catch (Exception x) { log.Debug($"LongST: Setvalue({value}), problem: {x}"); } return(false); }
/// <summary> /// SetValue: change to value from another ScaledType, check for convertability of scales and rescale the new value. /// </summary> /// <param name="value">New value (possibly in different scale)</param> /// <returns>True if scales were convertable and a new value is set.</returns> public override bool SetValueScaled(ScaledType value) { if (ReferenceEquals(this, value)) { return(true); } try { var v1 = (value is DoubleST) ? value as DoubleST : new DoubleST((double)value.GetValue(), value.GetScale()); return(SetValueScaled(v1, (DoubleST v2) => { Value = (v2 == null) ? v1.Value : v2.Value; })); } catch (Exception x) { log.Debug($"DoubleST: SetvalueScaled({value}), problem: {x}"); } return(false); }
/// <summary> /// Append: Multiply (or divide) this Scale with an extra factor /// </summary> /// <param name="other">Scale to append to this Scale</param> /// <param name="reciproce">true: append [scale^-1] else append [scale]</param> public void Append(ScaledType other, bool reciproce = false) { Append(other.Scale, reciproce); }
/// <summary> /// SetValue: change to value from another ScaledType, check for convertability of scales and rescale the new value. /// </summary> /// <param name="value">New value (possibly in different scale)</param> /// <returns>True if scales were convertable and a new value is set.</returns> public abstract bool SetValueScaled(ScaledType value);