將參數化對象分配給類類型屬性合同時出現錯誤。以下是代碼。如何將參數化構造函數對象分配給接口
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 =新MenuRoute(strRoute,真)
}
return displayContent;
}
}
請幫