将参数化对象分配给类类型属性合约时出错。以下是代码。
internal interface IDisplayContents : IHttpHandler
{
MenuRoute propMenuRoute { get; set; }
}
public class MenuRoute
{
private string _OriginalRoute = string.Empty;
private string[] _RouteNodes = null;
private bool _RouteFound;
public string OriginalRoute
{
get { return _OriginalRoute; }
}
public string[] RouteNodes
{
get { return _RouteNodes; }
}
public bool RouteFound
{
get { return _RouteFound; }
}
public MenuRoute(string route, bool routeFound)
{
_RouteFound = routeFound;
_RouteNodes = GlobalObjects.SplitString(route,"/");
if (_RouteNodes.Length .Equals(0))
_RouteNodes = new string[] { "/" };
for (int nodeIndex = 0; nodeIndex <= _RouteNodes.Length - 1; nodeIndex++)
{
_RouteNodes[nodeIndex] = GlobalObjects.SplitString(_RouteNodes[nodeIndex].ToString(), ".aspx")[0];
}
_OriginalRoute = route;
}
public class UrlRouteHandler : IRouteHandler
{
private string _virtualPath;
public UrlRouteHandler(string virtualPath)
{
_virtualPath = virtualPath;
}
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
IDisplayContents displayContent = BuildManager.CreateInstanceFromVirtualPath(_virtualPath, typeof(Page)) as IDisplayContents;
if (requestContext.RouteData.Values["notImplementedUrl"] != null)
{
displayContent.propMenuRoute = new MenuRoute("", false);
}
else
{
RouteValueDictionary routes = requestContext.RouteData.Values;
int intLevels = routes.Count;
string strRoute = string.Empty;
for (int intIterate = 1; intIterate <= intLevels; intIterate++)
{
strRoute += routes["level" + intIterate.ToString()] as string + "/";
}
displayContent.propMenuRoute = new MenuRoute(strRoute, true);
There comes the error
发生了System.NullReferenceException类型的异常但未在用户代码中处理
附加信息:未将对象引用设置为对象的实例。 displayContent.MenuRoute = New MenuRoute(strRoute,True)
}
return displayContent;
}
}
请帮忙