Generic extension method : Type argument cannot be inferred from the usage

前端 未结 3 1660
悲&欢浪女
悲&欢浪女 2020-12-06 05:06

I\'m trying to create a generic extension method, that works on typed data tables :

public static class Extensions
{
    public static TableType DoSomething&         


        
3条回答
  •  旧巷少年郎
    2020-12-06 06:00

    Even if that wasn't ideal, I gave up trying to return anything at all which allows me to do something like the following:

    public static void DoSomething(this TypedTableBase table, param Expression>[] predicates)
        where RowType : DataRow
        {
            // do something to each row of the table where the row matches the predicates
            // do not return the table... too bad for chaining commands
        }
    

    And then use it like so:

    MyTypedDataSet.MyTypedDataTable table = new MyTypedDataSet.MyTypedDataTable();
    table.DoSomething(row => row.Field1 == "foo"));
    

    and the compiler infers the type correctly.

    Thank you both for your answers.

提交回复
热议问题