コード例 #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
ファイル: GenericList.cs プロジェクト: yantrabuddhi/boo
        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()));
 }