ERROR Static method requires null instance, non-static method requires non-null instance

前端 未结 1 473
小鲜肉
小鲜肉 2021-01-18 03:41

I am trying to create an expression tree. I need to read data from a data table and check its columns. The columns to be checked and also the number of columns to be checke

相关标签:
1条回答
  • 2021-01-18 04:15

    It means the method call you're trying to represent is a static one, but you're giving it a target expression. That's like trying to call:

    Thread t = new Thread(...);
    // Invalid!
    t.Sleep(1000);
    

    You're sort of trying to do that in expression tree form, which isn't allowed either.

    It looks like this is happening for the Field extension method on DataRowExtensions - so the "target" of the extension method needs to be expressed as the first argument to the call, because you actually want to call:

    DataRowExtensions.Field<T>(row, col);
    

    So you want:

    inner = Expression.Call(mi, rowexp, colexp);
    

    That will call this overload which is the way to call a static method with two arguments.

    0 讨论(0)
提交回复
热议问题