// This file contains all the code required to compile autofac // http://autofac.googlecode.com/svn/trunk/src (revision 109) // while targeting .NET 2.0 framework // // The code simply comes from the System.Core assembly. // // Exclude the file (disable with directives) and switch the // target framework to .NET 3.5 - it should still compile. // // The original topic is here: // http://rabdullin.com/one-more-interesting-and-fresh-net-ioc-container-autofac/ // Rinat Abdullin. http://rabdullin.com // // Note: normally you should never put mutiple namespaces/classes into a single file using System; using System.Collections.Generic; using System.Runtime.InteropServices; namespace System { public delegate TRes Func(TSrc src); } namespace System.Runtime.CompilerServices { public class ExtensionAttribute : Attribute { } } namespace System.Linq { public static class Enumerable { public static IEnumerable Where( this IEnumerable source, Func predicate) { List res = new List(); foreach (TSrc s in source) { if (predicate(s)) { res.Add(s); } } return res; } public static IEnumerable Select( this IEnumerable source, Func selector) { List res = new List(); foreach (TSrc s in source) { TRes t = selector(s); res.Add(t); } return res; } public static int Count(this IEnumerable source) { if (source == null) { throw new ArgumentNullException("source"); } ICollection is2 = source as ICollection; if (is2 != null) { return is2.Count; } int num = 0; using (IEnumerator enumerator = source.GetEnumerator()) { while (enumerator.MoveNext()) { num++; } } return num; } public static TSource[] ToArray(this IEnumerable source) { if (source == null) { throw new ArgumentNullException("source"); } Buffer buffer = new Buffer(source); return buffer.ToArray(); } public static bool Contains(this IEnumerable source, TSource value) { ICollection is2 = source as ICollection; if (is2 != null) { return is2.Contains(value); } return source.Contains(value, null); } public static bool Contains(this IEnumerable source, TSource value, IEqualityComparer comparer) { if (comparer == null) { comparer = EqualityComparer.Default; } if (source == null) { throw new ArgumentNullException("source"); } foreach (TSource local in source) { if (comparer.Equals(local, value)) { return true; } } return false; } public static int Count(this IEnumerable source, Func predicate) { if (source == null) { throw new ArgumentNullException("source"); } if (predicate == null) { throw new ArgumentNullException("predicate"); } int num = 0; foreach (TSource local in source) { if (predicate(local)) { num++; } } return num; } } [StructLayout(LayoutKind.Sequential)] internal struct Buffer { internal TElement[] items; internal int count; internal Buffer(IEnumerable source) { TElement[] array = null; int length = 0; ICollection is2 = source as ICollection; if (is2 != null) { length = is2.Count; if (length > 0) { array = new TElement[length]; is2.CopyTo(array, 0); } } else { foreach (TElement local in source) { if (array == null) { array = new TElement[4]; } else if (array.Length == length) { TElement[] destinationArray = new TElement[length * 2]; Array.Copy(array, 0, destinationArray, 0, length); array = destinationArray; } array[length] = local; length++; } } this.items = array; this.count = length; } internal TElement[] ToArray() { if (this.count == 0) { return new TElement[0]; } if (this.items.Length == this.count) { return this.items; } TElement[] destinationArray = new TElement[this.count]; Array.Copy(this.items, 0, destinationArray, 0, this.count); return destinationArray; } } }