[.NET] CastingEnumerable(2)
39 Console.ReadLine();
40 }
41
42 static IEnumerable<Data> CreateDataList(IEnumerable<User> userList, string decorator)
43 {
44 return new CastingEnumerable<Data, User>(userList, delegate(User user) { return CreateData(user, decorator); });
45 }
46
47 static Data CreateData(User user, string decorator)
48 {
49 Data data = new Data();
50 data.DisplayName = decorator + user.LastName + "." + user.FirstName + decorator;
51 return data;
52 }
53 }
54 }
程式碼 :
view source
01 namespace CLK.Collections
02 {
03 public class CastingEnumerable<TResult, TSource> : IEnumerable<TResult>
04 {
05 //Properties
06 private readonly IEnumerable<TSource> _sourceEnumerable;
07
08 private CastingEnumerableDelegate<TResult, TSource> _enumerableDelegate;
09
10
11 // Construction
12 public CastingEnumerable(IEnumerable<TSource> sourceEnumerable, CastingEnumerableDelegate<TResult, TSource> enumerableDelegate)
13 {
14 #region Require
15
16 if (sourceEnumerable == null) throw new ArgumentNullException();
17 if (enumerableDelegate == null) throw new ArgumentNullException();
18
19 #endregion
20 _sourceEnumerable = sourceEnumerable;
21 _enumerableDelegate = enumerableDelegate;
相关新闻>>
- 发表评论
-
- 最新评论 更多>>