コード例 #1
0
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            SingleValueFactory asSingleValueFactory = obj as SingleValueFactory;

            return(asSingleValueFactory != null &&
                   EqualsImplementationUtils.SafeEquals(_theValue, asSingleValueFactory._theValue));
        }
コード例 #2
0
        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            ValueFactoryWithOptionalConcreteValue asMyType = obj as ValueFactoryWithOptionalConcreteValue;

            return(asMyType != null &&
                   _valueFactory.Equals(asMyType._valueFactory) &&
                   _isConcrete == asMyType._isConcrete &&
                   (_isConcrete ? EqualsImplementationUtils.SafeEquals(_value, asMyType._value) : true));
        }
コード例 #3
0
 /// <summary>
 /// Determines whether this vector and the specified second vector are equivalent.
 /// </summary>
 /// <param name="secondVector">The second vector.</param>
 /// <returns>
 ///     <c>true</c> if the specified second vector is equivalent; otherwise, <c>false</c>.
 /// </returns>
 /// <remarks>
 ///     <para>
 /// Two vectors are considered equivalent if they have the same dimensions
 /// (dimensions are the same if they refer to the same physical objects),
 /// and for each dimension, either the categories are equal or the values are equal.
 /// </para>
 ///     <para>
 /// This method is symmetric, transitive and reflexive (an equivalence relation).
 /// </para>
 /// </remarks>
 public bool IsEquivalent(Vector secondVector)
 {
     if (secondVector == null)
     {
         return(false);                // Mimic the recommended Object.Equals behavior
     }
     if (_dimensionValues.Count != secondVector._dimensionValues.Count)
     {
         return(false);
     }
     foreach (Dimension dimension in _dimensionValues.Keys)
     {
         if (!secondVector._dimensionValues.ContainsKey(dimension))
         {
             return(false);
         }
         if (_dimensionValues[dimension].IsConcrete && secondVector._dimensionValues[dimension].IsConcrete)
         {
             Vector asInnerFirstVector, asInnerSecondVector;
             if ((asInnerFirstVector = _dimensionValues[dimension].GetConcreteValue() as Vector) != null &&
                 (asInnerSecondVector = secondVector._dimensionValues[dimension].GetConcreteValue() as Vector) != null)
             {
                 if (!asInnerFirstVector.IsEquivalent(asInnerSecondVector))
                 {
                     return(false);
                 }
             }
             else if (!EqualsImplementationUtils.SafeEquals(_dimensionValues[dimension].GetConcreteValue(), secondVector._dimensionValues[dimension].GetConcreteValue()) &&
                      !_dimensionValues[dimension].ValueFactory.Equals(secondVector._dimensionValues[dimension].ValueFactory))
             {
                 return(false);
             }
         }
         else
         {
             if (!_dimensionValues[dimension].ValueFactory.Equals(secondVector._dimensionValues[dimension].ValueFactory))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
コード例 #4
0
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 public override int GetHashCode()
 {
     return(unchecked (_isConcrete.GetHashCode() + _valueFactory.GetHashCode() + EqualsImplementationUtils.GetSafeHashValue(_value)));
 }
コード例 #5
0
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 public override int GetHashCode()
 {
     return(EqualsImplementationUtils.GetSafeHashValue(_theValue));
 }