Skip to content

Add an overload to the "ToDynamicList" method which accepts a Type #48

@rpaschoal

Description

@rpaschoal

Hello @StefH,

Is it possible to add a new overload to the existing "ToDynamicList" extension method which accepts an instance of a Type class in order to return a typed list?

This may also come as an enhancement to the library itself since most people use it for dynamic operations which they may only know the type of their data at runtime.

As a workaround for now I did the following which is a bit nasty but it is working:

var genericTypeArgument = resultProperty.GetType().GetTypeInfo().GenericTypeArguments[0];

var method = typeof(DynamicEnumerableExtensions).GetMethods().Where(x => x.Name == "ToDynamicList" && x.IsGenericMethod == true).First();

var dynamicQueriedResult = resultProperty.Where(filters);

resultProperty = method.MakeGenericMethod(genericTypeArgument).Invoke(dynamicQueriedResult, new object[] { dynamicQueriedResult});

Many Thanks!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions