【发布时间】:2010-12-15 20:04:52
【问题描述】:
我正在制作我购买的书中的样本。而且,由于未知原因,我收到以下错误消息“找不到源类型'System.Type'的查询模式的实现。'Where' not found.”
VS2008 帮助说我需要添加 System.Linq 和 System.Collections 命名空间来解决问题。不幸的是,我仍然收到相同的错误消息。在 MSDN 论坛中,它说我需要将 EnforceConstraints 设置为 true;
我想知道什么是“EnforceConstraints”以及我该怎么做。
谢谢。
这里是代码
使用系统; 使用 System.Data; 使用 System.Configuration; 使用 System.Linq; 使用 System.Web; 使用 System.Web.Security; 使用 System.Web.UI; 使用 System.Web.UI.HtmlControls; 使用 System.Web.UI.WebControls; 使用 System.Web.UI.WebControls.WebParts; 使用 System.Xml.Linq; 使用 System.Web.Mvc; 使用 Castle.Windsor; 使用 Castle.Windsor.Configuration.Interpreters; 使用 Castle.Core.Resource; 使用 System.Reflection; 使用 Castle.Core; 使用 System.Collections;
命名空间WebUI { 公共类 WindsorControllerFactory : DefaultControllerFactory { WindsorContainer 容器;
public WindsorControllerFactory()
{
//Instatiate a container, taking configuration from web.conf
Container = new WindsorContainer(
new XmlInterpreter(new ConfigResource("Castle"))
);
//Also register all the controller types as transient
var controllerTypes =
from t in Assembly.GetExecutingAssembly().GetType()
where typeof(IController).IsAssignableFrom(t)
select t;
foreach (Type t in controllerTypes)
Container.AddComponentWithLifestyle(t.FullName, t, LifestyleType.Transient);
}
//Constructs the controller instance needed to service each request
protected override IController GetControllerInstance(Type controllerType)
{
return (IController)Container.Resolve(controllerType);
}
}//The constructor
}
示例在第 98 页。
这本书是“Pro ASP.NET MVC Framework”/Steven Sanderson/APress ISBN-13 (pbk): 978-1-4302-1007-8
【问题讨论】:
-
你能发布代码示例吗?
标签: c# linq visual-studio-2008 system.type