/// <summary>
        /// This gives sub-classes the chance to directly override, control or otherwise tamper 
        /// with the matching process.  This is also where normal matching is performed,
        /// so to replace it, simply don't call the base.OnMatch method.  To tweak the results,
        /// the base method should be performed first, and the results can then be modified.
        /// </summary>
        /// <param name="other"></param>
        /// <param name="mismatchedProperties"></param>
        /// <returns></returns>
        protected virtual bool OnMatch(IProjMatchable other, List<string> mismatchedProperties)
        {
            Type original = GetType();
            Type copy = other.GetType();
           
            // Public Properties ------------------------------------------------------
            PropertyInfo[] originalProperties = original.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            PropertyInfo[] copyProperties = copy.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo originalProperty in originalProperties)
            {
                if (copyProperties.Contains(originalProperty.Name) == false)
                {
                    mismatchedProperties.Add(originalProperty.Name);
                    continue;
                }
                PropertyInfo copyProperty = copyProperties.GetFirst(originalProperty.Name);
                if (copyProperty == null)
                {
                    // The name of the property was not found on the other object
                    mismatchedProperties.Add(originalProperty.Name);
                    continue;
                }

                object originalValue = originalProperty.GetValue(this, null);
                object copyValue = copyProperty.GetValue(other, null);
                if (Match(originalValue, copyValue) == false)
                {
                    mismatchedProperties.Add(originalProperty.Name);
                }
            }

            // Public Fields ---------------------------------------------------------
            FieldInfo[] originalFields = original.GetFields(BindingFlags.Public | BindingFlags.Instance);
            FieldInfo[] copyFields = copy.GetFields(BindingFlags.Public | BindingFlags.Instance);
            foreach (FieldInfo originalField in originalFields)
            {
                if (copyFields.Contains(originalField.Name) == false)
                {
                    mismatchedProperties.Add(originalField.Name);
                    continue;
                }

                FieldInfo copyField = copyFields.GetFirst(originalField.Name);
                if (copyField == null)
                {
                    mismatchedProperties.Add(originalField.Name);
                    continue;
                }

                object originalValue = originalField.GetValue(this);
                object copyValue = copyField.GetValue(other);
                if (Match(originalValue, copyValue) == false)
                {
                    mismatchedProperties.Add(originalField.Name);
                }
            }
            if (mismatchedProperties.Count > 0)
            {
                return false;
            }
            return true;
        }
Exemple #2
0
        /// <summary>
        /// This gives sub-classes the chance to directly override, control or otherwise tamper
        /// with the matching process.  This is also where normal matching is performed,
        /// so to replace it, simply don't call the base.OnMatch method.  To tweak the results,
        /// the base method should be performed first, and the results can then be modified.
        /// </summary>
        /// <param name="other"></param>
        /// <param name="mismatchedProperties"></param>
        /// <returns></returns>
        protected virtual bool OnMatch(IProjMatchable other, List <string> mismatchedProperties)
        {
            Type original = GetType();
            Type copy     = other.GetType();

            // Public Properties ------------------------------------------------------
            PropertyInfo[] originalProperties = original.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            PropertyInfo[] copyProperties     = copy.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo originalProperty in originalProperties)
            {
                if (copyProperties.Contains(originalProperty.Name) == false)
                {
                    mismatchedProperties.Add(originalProperty.Name);
                    continue;
                }
                PropertyInfo copyProperty = copyProperties.GetFirst(originalProperty.Name);
                if (copyProperty == null)
                {
                    // The name of the property was not found on the other object
                    mismatchedProperties.Add(originalProperty.Name);
                    continue;
                }

                object originalValue = originalProperty.GetValue(this, null);
                object copyValue     = copyProperty.GetValue(other, null);
                if (Match(originalValue, copyValue) == false)
                {
                    mismatchedProperties.Add(originalProperty.Name);
                }
            }

            // Public Fields ---------------------------------------------------------
            FieldInfo[] originalFields = original.GetFields(BindingFlags.Public | BindingFlags.Instance);
            FieldInfo[] copyFields     = copy.GetFields(BindingFlags.Public | BindingFlags.Instance);
            foreach (FieldInfo originalField in originalFields)
            {
                if (copyFields.Contains(originalField.Name) == false)
                {
                    mismatchedProperties.Add(originalField.Name);
                    continue;
                }

                FieldInfo copyField = copyFields.GetFirst(originalField.Name);
                if (copyField == null)
                {
                    mismatchedProperties.Add(originalField.Name);
                    continue;
                }

                object originalValue = originalField.GetValue(this);
                object copyValue     = copyField.GetValue(other);
                if (Match(originalValue, copyValue) == false)
                {
                    mismatchedProperties.Add(originalField.Name);
                }
            }
            if (mismatchedProperties.Count > 0)
            {
                return(false);
            }
            return(true);
        }