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); }
//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); }
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)); }
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); }
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)); }
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); }
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); }
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); }
private static T Coerce(object value) { if (value is T) { return((T)value); } return((T)RuntimeServices.Coerce(value, typeof(T))); }
public int IndexOf(object item) { for (int i = 0; i < _count; ++i) { if (RuntimeServices.EqualityOperator(_items[i], item)) { return(i); } } return(-1); }
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)); }
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); }
private static IEnumerator GetEnumerator(object enumerable) { return(RuntimeServices.GetEnumerable(enumerable).GetEnumerator()); }
public static IEnumerable iterator(object enumerable) { return(RuntimeServices.GetEnumerable(enumerable)); }
//[EnumeratorItemType(Type.GetType("System.Object[]"))] public static IEnumerable enumerate(object enumerable) { return(new EnumerateEnumerator(RuntimeServices.GetEnumerable(enumerable).GetEnumerator())); }