Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# using params and extension methods

Is the params keyword really not supported within extension methods?

I have found that when I create extension methods with the params keyword, that I get "No overloaded method for X takes 2 arguments". Intellisense recognizes the extension method and even knows that it needs an object array.

Here's some sample code:

public static DalRow EasyRetrieveSingle(this DalRow dalRow, object[] parameters) 
{
    Dictionary<string, object> dic = new Dictionary<string, object>();
    for (int i = 0; i < parameters.Length; i += 2)
        dic.Add(parameters[i].ToString(), parameters[i + 1]);

    List<DalRow> list = DalRow.RetrieveByFieldValues(dalRow.Structure, null, dic).Cast<DalRow>().ToList();
    if (list.Count == 0) return null;
    return list[0];
}

Here's some sample code that calls it (to no avail)

(new X()).EasyRetrieveSingle(1, 2);
like image 741
Daniel Avatar asked Sep 21 '09 23:09

Daniel


1 Answers

It looks like you're missing the params keyword...

public static DalRow EasyRetrieveSingle(this DalRow dalRow, params object[] parameters) 
like image 116
Yuliy Avatar answered Sep 19 '22 07:09

Yuliy