Example #1
0
        /// <summary>
        /// Determine if this instance of PQ semantically equals another
        /// instance of a data type.
        /// </summary>
        public override BL SemanticEquals(IAny other)
        {
            // Base equality
            var baseEq = base.SemanticEquals(other);

            if (!(bool)baseEq)
            {
                return(baseEq);
            }

            // Values are equal?
            PQ pqOther = other as PQ;

            if (pqOther == null)
            {
                return(false);
            }
            else if (this.Value.HasValue && pqOther.Value.HasValue)
            {
                return(pqOther.Convert(this.Unit).Value.Value == this.Value.Value);
            }
            else if (this.UncertainRange != null && !this.UncertainRange.IsNull &&
                     pqOther.UncertainRange != null && !pqOther.UncertainRange.IsNull)
            {
                return(this.UncertainRange.Equals(pqOther.UncertainRange));
            }
            return(false);
        }
Example #2
0
 /// <summary>
 /// Compares this PQ to another PQ
 /// </summary>
 /// <exception cref="T:System.ArgumentException">When the units of both PQ instances do not match</exception>
 public int CompareTo(PQ other)
 {
     if (other == null || other.IsNull)
     {
         return(1);
     }
     else if (this.IsNull && !other.IsNull)
     {
         return(-1);
     }
     else if (this.Value.HasValue && !other.Value.HasValue)
     {
         return(1);
     }
     else if (other.Value.HasValue && !this.Value.HasValue)
     {
         return(-1);
     }
     else if (!other.Value.HasValue && !this.Value.HasValue)
     {
         return(0);
     }
     else if (!this.IsUnitComparable(other.Unit))
     {
         throw new ArgumentException("Units must match to compare PQ");
     }
     else
     {
         return(this.Value.Value.CompareTo(other.Convert(this.Unit).Value.Value));
     }
 }