Skip to content

Commit 21d9969

Browse files
Tyler CarlsonTyler Carlson
authored andcommitted
Added For without generics so can pass over type
1 parent c03f1ba commit 21d9969

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

  • src/AutoMapper.Collection/AutoMapper.Collection.EntityFramework

src/AutoMapper.Collection/AutoMapper.Collection.EntityFramework/Extensions.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System.Data.Entity;
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Data.Entity;
5+
using AutoMapper.QueryableExtensions.Impl;
26

37
namespace AutoMapper.EntityFramework
48
{
@@ -15,5 +19,21 @@ public static IPersistance Persist<TSource>(this DbSet<TSource> source)
1519
{
1620
return new Persistance<TSource>(source, Mapper.Engine);
1721
}
22+
23+
/// <summary>
24+
/// Non Generic call for For
25+
/// </summary>
26+
/// <typeparam name="TSource"></typeparam>
27+
/// <param name="source"></param>
28+
/// <param name="destType"></param>
29+
/// <returns></returns>
30+
public static IEnumerable For<TSource>(this IQueryDataSourceInjection<TSource> source, Type destType)
31+
{
32+
var forMethod = source.GetType().GetMethod("For").MakeGenericMethod(destType);
33+
var listType = typeof(List<>).MakeGenericType(destType);
34+
var forResult = forMethod.Invoke(source, new object[] { null });
35+
var enumeratedResult = Activator.CreateInstance(listType, forResult);
36+
return enumeratedResult as IEnumerable;
37+
}
1838
}
1939
}

0 commit comments

Comments
 (0)