0

I have a generic method that has several parameters plus a return type:

    public static class Support
{
    public static TR JSONKeyName<TR, T1, T2, T3>(this IEnumerable<Tuple<T1, T2>> a, Action<T3> b)
    {
        TR result = default(TR);

        try
        {
            foreach (var entry in a)
            {
                b((T3)TypeDescriptor.GetConverter(typeof(T3)).ConvertFromInvariantString("[ \"" + entry.Item1 + "\", " + entry.Item2 + "\" ]"));
            }

            result = (TR)Convert.ChangeType(true, typeof(TR));
        }
        catch
        {
            result = (TR)Convert.ChangeType(false, typeof(TR));
        }

        return result;
    }
}       


List<Tuple<int, string>> list = new List<Tuple<int, string>>();
list.Add(new Tuple<int, string>(1, "Test 1"));
list.Add(new Tuple<int, string>(2, "Test 2"));
list.Add(new Tuple<int, string>(3, "Test 3"));

var res = list.JSONKeyName<bool>((string entry) =>
    {


    });

When calling JSONKeyName from the example above I get the following error:

The compiler error is:

*Using the generic method requires 4 type arguments

3
  • 2
    The method has 4 type parameters, so it requires 4 type arguments... where is the confusion? Commented Mar 7, 2013 at 5:33
  • I understand what the error is saying. But one of the parameter is for the return type which is TR. So I may be using it wrong. Im a bit new to using generics so I may have the code wrong Commented Mar 7, 2013 at 5:35
  • Yes but you need to specify T1, T2, and T3, also. Commented Mar 7, 2013 at 5:35

1 Answer 1

2

Er, you've noticed that it takes multiple arguments, and you're obviously passing it only one — bool. Change it to list.JSONKeyName<bool, int, string, string>, as per the context.

Sign up to request clarification or add additional context in comments.

1 Comment

OK i get it now. Thanks all for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.