示例#1
0
        /// <summary>
        /// This method does a comparison of the actual contents of two property bags
        /// and returns True if they are equal, else False.  Equality means that 
        /// the two collections contain the same set of property names (case insensitive)
        /// with the same values (case sensitive).
        /// Requires property group to be virtual.
        /// </summary>
        /// <param name="compareToPropertyGroup"></param>
        /// <owner>RGoel</owner>
        /// <returns>true if the two property bags are equivalent, and false otherwise.</returns>
        internal bool IsEquivalent
        (
            BuildPropertyGroup compareToPropertyGroup
        )
        {
            ErrorUtilities.VerifyThrow(compareToPropertyGroup != null, "Received a null propertyBag!");

            // IsEquivalent is only supported for virtual PropertyGroups.
            this.MustBeVirtual("NeedVirtualPropertyGroup");
            compareToPropertyGroup.MustBeVirtual("NeedVirtualPropertyGroup");

            // Reference equality is easy
            if (this == compareToPropertyGroup)
            {
                return true;
            }

            // First check if the sizes of the two bags match.  If they don't,
            // we don't need to do anything further.
            bool isEqual = true;
            if (this.Count == compareToPropertyGroup.Count)
            {
                // If both bags do have the same number of elements, it should
                // be sufficient to check if one bag contains all of the 
                // elements in the other.
                foreach (DictionaryEntry entry in this.propertyTableByName)
                {
                    BuildProperty leftProperty = (BuildProperty)entry.Value;

                    ErrorUtilities.VerifyThrow(leftProperty != null, "How can we have a null entry in the hash table?");

                    BuildProperty rightProperty = compareToPropertyGroup[(string)entry.Key];

                    if (!leftProperty.IsEquivalent(rightProperty))
                    {
                        isEqual = false;
                        break;
                    }
                }
            }
            else
            {
                // Sizes are unequal
                isEqual = false;
            }

            return isEqual;
        }