Example #1
0
        public virtual long count()
        {
            if (isArrayIterator)
            {
                return(_array.Count);
            }
            else if (isObjectIterator)
            {
                return(TypeMembersUtils.FieldsCount(_dobj));
            }

            return(0);
        }
Example #2
0
        /// <summary>
        /// Compares two class instances.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="comparer">The comparer.</param>
        /// <param name="incomparable">
        /// Whether objects are incomparable while no difference is found before both objects enter an infinite recursion, returns zero.
        /// </param>
        static int CompareObjects(object x, object y, PhpComparer comparer, out bool incomparable)
        {
            Debug.Assert(x != null && y != null);

            incomparable = false;

            // check for same instance
            if (ReferenceEquals(x, y))
            {
                return(0);
            }

            // check for different types
            var type_x = x.GetType().GetTypeInfo();
            var type_y = y.GetType().GetTypeInfo();

            if (type_x != type_y)
            {
                if (type_x.IsSubclassOf(type_y.AsType()))
                {
                    return(-1);
                }
                if (type_y.IsSubclassOf(type_x.AsType()))
                {
                    return(1);
                }

                incomparable = true;
                return(1); // they really are incomparable
            }

            // check for different number of fields
            int result = TypeMembersUtils.FieldsCount(x) - TypeMembersUtils.FieldsCount(y);

            if (result != 0)
            {
                return(result);
            }

            throw new NotImplementedException();
        }