forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMvcWebPageRazorHost.cs
More file actions
67 lines (60 loc) · 2.71 KB
/
Copy pathMvcWebPageRazorHost.cs
File metadata and controls
67 lines (60 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Web.Razor.Generator;
using System.Web.Razor.Parser;
using System.Web.WebPages.Razor;
namespace System.Web.Mvc.Razor
{
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "WebPage", Justification = "The class name is derived from the name of the base type")]
public class MvcWebPageRazorHost : WebPageRazorHost
{
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "The NamespaceImports property should not be virtual. This is a temporary fix.")]
public MvcWebPageRazorHost(string virtualPath, string physicalPath)
: base(virtualPath, physicalPath)
{
RegisterSpecialFile(RazorViewEngine.ViewStartFileName, typeof(ViewStartPage));
DefaultPageBaseClass = typeof(WebViewPage).FullName;
// REVIEW get rid of the namespace import to not force additional references in default MVC projects
GetRidOfNamespace("System.Web.WebPages.Html");
}
public override RazorCodeGenerator DecorateCodeGenerator(RazorCodeGenerator incomingCodeGenerator)
{
if (incomingCodeGenerator is CSharpRazorCodeGenerator)
{
return new MvcCSharpRazorCodeGenerator(incomingCodeGenerator.ClassName,
incomingCodeGenerator.RootNamespaceName,
incomingCodeGenerator.SourceFileName,
incomingCodeGenerator.Host);
}
else
{
return base.DecorateCodeGenerator(incomingCodeGenerator);
}
}
public override ParserBase DecorateCodeParser(ParserBase incomingCodeParser)
{
if (incomingCodeParser is CSharpCodeParser)
{
return new MvcCSharpRazorCodeParser();
}
else if (incomingCodeParser is VBCodeParser)
{
return new MvcVBRazorCodeParser();
}
else
{
return base.DecorateCodeParser(incomingCodeParser);
}
}
private void GetRidOfNamespace(string ns)
{
Debug.Assert(NamespaceImports.Contains(ns), ns + " is not a default namespace anymore");
if (NamespaceImports.Contains(ns))
{
NamespaceImports.Remove(ns);
}
}
}
}