Linq Expression Confusion combined with defered execution

Question!

I'm trying to figure out a way of getting a particular piece of code called when a path is recognised. I'm going to be registering paths from different plugins. This allows them to fight over the paths that they want.

The idea being that the plugins say here are the paths that I'm interested in, when you get a match create an instance of this class and call this method on it to return a view.

I can figure out enough to be able to pass in a delegate and then call the appropriate code but that still leaves me holding a pointer to the class. I specifically don't want that. I want to instance the class required and then call the described method.

Here is an outline:

public class TestView : IView
{
    public void Render(ViewContext viewContext, System.IO.TextWriter writer) {}
}

class TestViewCreator
{
    public IView CreateView(object Arguments)
    {
        return new TestView();
    }
}

public class CentralStash
{
    // T = TestViewCreator
    // How do I describe the method I want to call (CreateView)?
    public void RegisterPath<T>(string url, object Arguements)
    {

    }

    public IView GetView(string url)
    {
        var viewCreator = ObjectFactory.GetInstance<T>();
        //How do I call the method description on the type that I have jsut instanced?
        return null;
    }
}

I've got the feeling that I should probably be using routes here, or possibly an Expression? I know this is possible to do with delegates but I don't want loads of objects hanging round because of the pointers to them.

A nudge in the right direction would be appreciated.

Update:

I could of course just create the interface

public interface IViewCreator
{
    public IView CreateView(object Arguments);
}

And create one of them and call CreateView, I was hoping to make this more powerful that that though.



Answers
public IView GetView(string url)
{
    object viewCreatorObj = ObjectFactory.GetInstance<T>();
    TestViewCreator viewCreator=? viewCreatorObj as TestViewCreator;

    return viewCreator.CreateView(null);
}
By : 0699


Your code says

 Reviewers(N) = Sheets(N+1).Range("B7:C7").Value

Range B7:C7 consists of two cells, not one, and therefore the value is an array, not a single value. Use a range of one cell.



Or even, since Worksheets is 1-based (so we can lose that +1 and -1 business):

Dim i As Long
Dim reviewers() As String
ReDim reviewers(1 To Worksheets.Count)

For i = 1 To Worksheets.Count 
    reviewers(i) = Worksheets(i).Cells(1, 5).Value
Next


This video can help you solving your question :)
By: admin