I've got a generic method TResult Foo<TSource, TResult>(IEnumerable<TSource> source)
and if TResult
is declared as dynamic
I want to execute a different code path than for other type declarations.
For regular types you can do stuff like:
if (typeof(TResult) == typeof(int))
return ExpressionFactory.CreateExpandoFunction<TSource, TResult>();
But if (typeof(TResult) == typeof(dynamic))
does not compile.
Is there anyway to make this sort of determination at runtime when the method is called with the declaration:
dyanmic x = Foo<int, dynamic>(list);
Since dynamic itself isn't a type what should I be testing for? IDynamicMetaObjectProvider
?
EDIT
This is part of a SQL text to System.Linq.Expression evaluator. The specific desire to branch if TResult
is dynamic is for some pseudo logic that looks something like this:
if (type is struct)
create selector that initializes each element to result values
else if (type is class)
create selector that initialize each element to new instance and set member properties
else if (type is dynamic)
create selector that initializes each element to new `ExpandoObject` and populates/sets member properties