【问题标题】:Linq Expression Confusion combined with defered executionLinq 表达式混淆与延迟执行相结合
【发布时间】:2009-02-05 14:56:44
【问题描述】:

一旦路径与特定需求或模式匹配,我想执行代码的特定部分。我将从不同的插件中导入一些路径,这些路径将被搜索并整理出对我的意图有用或无用的路径。

这个想法是,一旦我从这些路径中获得匹配,我想创建这个类的一个实例并调用它的方法来返回一个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,但我希望让它更强大。

【问题讨论】:

  • 传递一个委托要好得多。不需要对象参数参数。还有一个代表开销?那么,如果你让它们传入字符串和类型参数并保存它们,你仍然有对象。
  • 这没有多大意义......如果你编辑它,我可能会回答。

标签: c# asp.net-mvc linq reflection routing


【解决方案1】:
public IView GetView(string url)
{
    object viewCreatorObj = ObjectFactory.GetInstance<T>();
    TestViewCreator viewCreator=? viewCreatorObj as TestViewCreator;

    return viewCreator.CreateView(null);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    • 2011-06-12
    相关资源
    最近更新 更多