Guest User

Untitled

a guest
Jan 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. return this.Elements.ReduceAll(symbols)
  2. // es = 配列の全要素 (評価済)
  3. .Let(es => es
  4. .Select(e => e.Type)
  5. .Distinct()
  6. // ts = 配列に含まれる全ての型
  7. .Let(ts => ts
  8. .SelectMany(t => t.GetConvertibleTypes())
  9. // 配列の要素の型から導ける全ての基底型、実装インターフェイスの集合を取得し
  10. .Distinct()
  11. // Object を取り除き、Object からの継承ルートの遠さで並び替え
  12. .Except(EnumerableEx.Return(typeof(Object)))
  13. .OrderByDescending(t => EnumerableEx
  14. .Generate(t, _ => _.BaseType != null, _ => _.BaseType, _ => _)
  15. .Count()
  16. )
  17. // 末尾に Object を追加
  18. .Concat(EnumerableEx.Return(typeof(Object)))
  19. // …したリストのうち、配列の全要素が互換性のある最初の型を選択
  20. .First(t => ts.All(t.IsAssignableFrom))
  21. )
  22. // t = 決定された配列の型
  23. .Let(t => NewArrayInit(
  24. t,
  25. // t が参照型の場合、値型の要素は明示的にキャストが必要
  26. t.IsValueType
  27. ? es
  28. : es.Select(e => e.Type.IsValueType
  29. ? Convert(e, t)
  30. : e
  31. )
  32. ))
  33. );
Add Comment
Please, Sign In to add comment