Patcher.Data.Plugins.Content.MemberInfo.Equate C# (CSharp) Method

Equate() public method

public Equate ( object one, object other ) : bool
one object
other object
return bool
        public bool Equate(object one, object other)
        {
            if (IsListType)
            {
                var listOne = (IList)GetValue(one);
                var listOther = (IList)GetValue(other);

                // Both null means equal
                if (listOne == null && listOther == null)
                    return true;

                // Only one of them null means not equal
                if (listOne == null || listOther == null)
                    return false;

                // Different lengths means different lists
                if (listOne.Count != listOther.Count)
                    return false;

                var itOne = listOne.GetEnumerator();
                var itOther = listOther.GetEnumerator();

                while (itOne.MoveNext() && itOther.MoveNext())
                {
                    if (IsPrimitiveType)
                    {
                        object oneValue = itOne.Current;
                        object otherValue = itOther.Current;
                        if (!oneValue.Equals(otherValue))
                            return false;
                    }
                    else
                    {
                        var fieldOne = (Field)itOne.Current;
                        var fieldOther = (Field)itOther.Current;
                        if (!fieldOne.Equals(fieldOther))
                            return false;
                    }
                }
            }
            else
            {
                if (IsPrimitiveType)
                {
                    object oneValue = GetValue(one);
                    object otherValue = GetValue(other);

                    // Both values are null means equal
                    if (oneValue == null && otherValue == null)
                        return true;

                    // One of the values is null means not equal
                    if (oneValue == null || otherValue == null)
                        return false;

                    // Both not null, consider each value
                    if (!oneValue.Equals(otherValue))
                        return false;
                }
                else
                {
                    var oneField = (Field)GetValue(one);
                    var otherField = (Field)GetValue(other);

                    // Both fields do not exists means equal
                    if (oneField == null && otherField == null)
                        return true;

                    // One of the fiels does not exist means not equal
                    if (oneField == null || otherField == null)
                        return false;

                    // Both fields exist, consider the content
                    if (!oneField.Equals(otherField))
                        return false;
                }
            }

            return true;
        }