Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
LambdaReadOnlyCollection.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections;
5 using System.Collections.Generic;
6 using System.Linq;
7 
8 namespace SiliconStudio.Paradox.Internals
9 {
10  class LambdaReadOnlyCollection<TSource, T> : IReadOnlyList<T>
11  {
12  private IReadOnlyList<TSource> source;
13  private Func<TSource, T> selector;
14 
15  public LambdaReadOnlyCollection(IReadOnlyList<TSource> source, Func<TSource, T> selector)
16  {
17  this.source = source;
18  this.selector = selector;
19  }
20 
21  /// <inheritdoc/>
22  IEnumerator IEnumerable.GetEnumerator()
23  {
24  return GetEnumerator();
25  }
26 
27  /// <inheritdoc/>
28  public IEnumerator<T> GetEnumerator()
29  {
30  return source.Select(x => selector(x)).GetEnumerator();
31  }
32 
33  /// <inheritdoc/>
34  public int Count { get { return source.Count; } }
35 
36  /// <inheritdoc/>
37  public T this[int index]
38  {
39  get { return selector(source[index]); }
40  }
41  }
42 }
LambdaReadOnlyCollection(IReadOnlyList< TSource > source, Func< TSource, T > selector)