0
我想在路徑匹配特定的需求或模式時執行代碼的特定部分。我將從不同的插件導入一些路徑,這些路徑將通過搜索並整理出來,這些路徑對我的意圖是有用的或者不是。Linq表達式混淆與被執行的結合
這個想法是,一旦我從這些pathes中獲得匹配,我想創建這個類的一個實例並調用它的返回view
的方法。
我可以弄清楚,能夠傳入一個委託並調用相應的代碼,但仍然留下一個指向我不想要的類的指針。我想創建這個類的一個實例並調用所需的方法。
這裏是一個輪廓:
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;
}
}
我已經得到了我應該在這裏使用的路線的感覺,或可能是體現在哪裏?我知道這可能與代表有關,但我不希望因爲他們的指示而放棄一些對象。
向正確的方向微調將不勝感激。
更新:
職高我可以創建界面:
public interface IViewCreator
{
public IView CreateView(object Arguments);
}
,創造他們的一個叫CreateView
,但我希望,使這個更加強大。
傳遞給委託人要好得多。不需要對象參數參數。還有一個委託開銷?那麼,如果你讓他們傳遞字符串並輸入參數並保存這些參數,那麼你仍然有對象。 – MichaelGG 2009-02-05 22:00:16