This project has moved. For the latest updates, please go here.

Problems with Overloaded Methods?

Topics: User Forum
Dec 9, 2006 at 9:07 AM
Marc,

This tool is an awesome idea!!! I have quite a few places where this could come in REAL handy.

So I was trying to check this out on a couple of routines that I have that use Reflection to see if I can improve performance a bit and I found that I couldn't get the Function logic to work when methods have more than one overload.

For example:

public class Test
{
public bool Load(int Value)
{
return true;
}
public bool Load(string Value)
{
return true;
}
}

then called with:

Test MyTest = new Test();

Func<Test, bool, int> Customer_Load = Dynamic<Test>.Instance.Function<bool>.Explicit<int>.CreateDelegate("Load");

bool Result = Customer_Load(MyTest,1000);

will fail with an "Ambigious Match Found"...


Dec 10, 2006 at 12:07 AM
Eh... never mind - figured it out...

Func<Test, bool, int> Customer_Load = Dynamic<Test>.Instance.Function<bool>.Explicit<int>.CreateDelegate("Load",ParameterList.Auto);
bool Result = Customer_Load(MyTest,1000);

does the trick...

+++ Rick ---
Coordinator
Dec 10, 2006 at 4:00 AM
That's certainly the best way :). If you do have an ambiguous match that you know the "right" method to call, you can simply lookup using Reflection to get the right MethodInfo and use that CreateDelegate call.