im trying to write some kind a strongly typed routing system. Imagine ive got some class with method A that takes and returns string
public class SomeClass
{
public string MethodA(string str)
{
return string.Format("SomeClass :: MethodA {0}", str);
}
}
And I want my main method to look like this
class Program
{
static void Main(string[] args)
{
var col = new SomeCollection();
col.Add<SomeClass>("url", c => c.MethodA("test")); //Bind MethodA to "url"
}
}
So my questions are:
- What should be Add method signature?
- How can I invoke MethodA in SomeCollection?
I guess it'll be something like
public class SomeCollection
{
public void Add<TController> (string url, Func<TController, string> exp)
{
// Add func to dictionary <url, funcs>
}
public void FindBestMatchAndExecute (Request request)
{
//Search url in collection and invoke it's method.
//Method params we can extract from request.
}
}