예제 #1
0
파일: List.cs 프로젝트: codehaus/boo
        override public bool Equals(object other)
        {
            if (other == this)
            {
                return(true);
            }

            List rhs = other as List;

            if (null == rhs)
            {
                return(false);
            }

            if (_count != rhs.Count)
            {
                return(false);
            }

            for (int i = 0; i < _count; ++i)
            {
                if (!RuntimeServices.EqualityOperator(_items[i], rhs[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        //fast path, that implementation detail does not really need to be API
        private static Array ArrayFromCollection(Type elementType, ICollection collection)
        {
            if (null == elementType)
            {
                throw new ArgumentNullException("elementType");
            }
            if (null == collection)
            {
                throw new ArgumentNullException("collection");
            }

            Array array = Array.CreateInstance(elementType, collection.Count);

            if (RuntimeServices.IsPromotableNumeric(Type.GetTypeCode(elementType)))
            {
                int i = 0;
                foreach (object item in collection)
                {
                    object value = RuntimeServices.CheckNumericPromotion(item).ToType(elementType, null);
                    array.SetValue(value, i);
                    ++i;
                }
            }
            else
            {
                collection.CopyTo(array, 0);
            }
            return(array);
        }
예제 #3
0
        public static Array array(Type elementType, IEnumerable enumerable)
        {
            if (null == elementType)
            {
                throw new ArgumentNullException("elementType");
            }
            if (null == enumerable)
            {
                throw new ArgumentNullException("enumerable");
            }

                        #pragma warning disable 618 //obsolete
            ICollection collection = enumerable as ICollection;
            if (null != collection)                 //fast path
            {
                return(ArrayFromCollection(elementType, collection));
            }
                        #pragma warning restore 618

            List l = null;
            if (RuntimeServices.IsPromotableNumeric(Type.GetTypeCode(elementType)))
            {
                l = new List();
                foreach (object item in enumerable)
                {
                    object value = RuntimeServices.CheckNumericPromotion(item).ToType(elementType, null);
                    l.Add(value);
                }
            }
            else
            {
                l = new List(enumerable);
            }
            return(l.ToArray(elementType));
        }
예제 #4
0
        public bool Equals(Hash other)
        {
            if (null == other)
            {
                return(false);
            }
            if (this == other)
            {
                return(true);
            }
            if (Count != other.Count)
            {
                return(false);
            }

            foreach (DictionaryEntry entry in other)
            {
                if (!ContainsKey(entry.Key))
                {
                    return(false);
                }
                if (!RuntimeServices.EqualityOperator(entry.Value, this[entry.Key]))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #5
0
        public static Array array(Type elementType, IEnumerable enumerable)
        {
            if (null == enumerable)
            {
                throw new ArgumentNullException("enumerable");
            }
            if (null == elementType)
            {
                throw new ArgumentNullException("elementType");
            }

            // future optimization, check EnumeratorItemType of enumerable
            // and get the fast path whenever possible
            List l = null;

            if (RuntimeServices.IsPromotableNumeric(Type.GetTypeCode(elementType)))
            {
                l = new List();
                foreach (object item in enumerable)
                {
                    object value = RuntimeServices.CheckNumericPromotion(item).ToType(elementType, null);
                    l.Add(value);
                }
            }
            else
            {
                l = new List(enumerable);
            }
            return(l.ToArray(elementType));
        }
예제 #6
0
        public bool Equals(List <T> other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            if (_count != other.Count)
            {
                return(false);
            }

            for (var i = 0; i < _count; ++i)
            {
                if (!RuntimeServices.EqualityOperator(_items[i], other[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #7
0
        public bool Equals(Hash other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(other, this))
            {
                return(true);
            }
            if (Count != other.Count)
            {
                return(false);
            }

            foreach (var entry in other)
            {
                if (!ContainsKey(entry.Key))
                {
                    return(false);
                }
                if (!RuntimeServices.EqualityOperator(entry.Value, this[entry.Key]))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #8
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }

            Hash other = (Hash)obj;

            if (Count != other.Count)
            {
                return(false);
            }

            foreach (DictionaryEntry entry in other)
            {
                if (!ContainsKey(entry.Key))
                {
                    return(false);
                }
                if (!RuntimeServices.EqualityOperator(entry.Value, this[entry.Key]))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #9
0
 private static T Coerce(object value)
 {
     if (value is T)
     {
         return((T)value);
     }
     return((T)RuntimeServices.Coerce(value, typeof(T)));
 }
예제 #10
0
파일: List.cs 프로젝트: codehaus/boo
 public int IndexOf(object item)
 {
     for (int i = 0; i < _count; ++i)
     {
         if (RuntimeServices.EqualityOperator(_items[i], item))
         {
             return(i);
         }
     }
     return(-1);
 }
예제 #11
0
 public static IEnumerable map(object enumerable, ICallable function)
 {
     if (null == enumerable)
     {
         throw new ArgumentNullException("enumerable");
     }
     if (null == function)
     {
         throw new ArgumentNullException("function");
     }
     return(new MapEnumerable(RuntimeServices.GetEnumerable(enumerable), function));
 }
예제 #12
0
        public bool Equals(List <T> other)
        {
            if (null == other)
            {
                return(false);
            }
            if (this == other)
            {
                return(true);
            }
            if (_count != other.Count)
            {
                return(false);
            }

            for (int i = 0; i < _count; ++i)
            {
                if (!RuntimeServices.EqualityOperator(_items[i], other[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #13
0
 private static IEnumerator GetEnumerator(object enumerable)
 {
     return(RuntimeServices.GetEnumerable(enumerable).GetEnumerator());
 }
예제 #14
0
 public static IEnumerable iterator(object enumerable)
 {
     return(RuntimeServices.GetEnumerable(enumerable));
 }
예제 #15
0
파일: Builtins.cs 프로젝트: codehaus/boo
 //[EnumeratorItemType(Type.GetType("System.Object[]"))]
 public static IEnumerable enumerate(object enumerable)
 {
     return(new EnumerateEnumerator(RuntimeServices.GetEnumerable(enumerable).GetEnumerator()));
 }