Call function in dynamic linq

后端 未结 7 938
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 21:13

I\'m trying to call a function in a dynamic linq select statement, but im getting error:

No property or field \'A\' exists in type \'Tuple2\'
7条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 21:45

    @Armand has put together a brilliant solution for this issue, and being the only solution I was able to find regarding this I want to add to it for anyone who tries the same approach.

    The class that is marked with...

    [DynamicLinqType] 
    

    ... must be taken into consideration when you run the following line:

    FindTypesMarkedWithDynamicLinqTypeAttribute(new[] { GetType().GetTypeInfo().Assembly })
    

    In the solution provided above, this assumes the class that contains the function to be evaluated is on the same class the code currently resides in. If the methods are to be used outside of said class, the assembly will need to change.

    FindTypesMarkedWithDynamicLinqTypeAttribute(new[] { typeof(AnotherClassName).Assembly })
    

    Nothing changes from the solution above, this is just for clarification for anyone attempting to use it.

提交回复
热议问题