1 //------------------------------------------------------------------------------
2 // <copyright file="BaseParser.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
8 * Implements the ASP.NET template parser
10 * Copyright (c) 1998 Microsoft Corporation
13 /*********************************
19 TemplateControlDependencyParser
21 UserControlDependencyParser
22 MasterPageDependencyParser
32 **********************************/
34 namespace System.Web.UI {
36 using System.Collections;
37 using System.Reflection;
38 using System.Web.Compilation;
39 using System.Web.Hosting;
40 using System.Web.Util;
41 using System.Text.RegularExpressions;
42 using System.Web.RegularExpressions;
43 using System.Security.Permissions;
45 // Internal interface for Parser that have exteranl assembly dependency.
46 internal interface IAssemblyDependencyParser {
47 ICollection AssemblyDependencies { get; }
52 /// <para>[To be supplied.]</para>
54 public class BaseParser {
56 // The directory used for relative path calculations
57 private VirtualPath _baseVirtualDir;
58 internal VirtualPath BaseVirtualDir {
59 get { return _baseVirtualDir; }
63 // The virtual path to the file currently being processed
64 private VirtualPath _currentVirtualPath;
65 internal VirtualPath CurrentVirtualPath {
66 get { return _currentVirtualPath; }
68 _currentVirtualPath = value;
70 // Can happen in the designer
71 if (value == null) return;
73 _baseVirtualDir = value.Parent;
77 internal string CurrentVirtualPathString {
78 get { return System.Web.VirtualPath.GetVirtualPathString(CurrentVirtualPath); }
81 private Regex _tagRegex;
82 // The 3.5 regex is used only when targeting 2.0/3.5 for backward compatibility (Dev10 bug 830783).
83 private readonly static Regex tagRegex35 = new TagRegex35();
84 // The 4.0 regex is used for web sites targeting 4.0 and above.
85 private readonly static Regex tagRegex40 = new TagRegex();
87 internal readonly static Regex directiveRegex = new DirectiveRegex();
88 internal readonly static Regex endtagRegex = new EndTagRegex();
89 internal readonly static Regex aspCodeRegex = new AspCodeRegex();
90 internal readonly static Regex aspExprRegex = new AspExprRegex();
91 internal readonly static Regex aspEncodedExprRegex = new AspEncodedExprRegex();
92 internal readonly static Regex databindExprRegex = new DatabindExprRegex();
93 internal readonly static Regex commentRegex = new CommentRegex();
94 internal readonly static Regex includeRegex = new IncludeRegex();
95 internal readonly static Regex textRegex = new TextRegex();
97 // Regexes used in DetectSpecialServerTagError
98 internal readonly static Regex gtRegex = new GTRegex();
99 internal readonly static Regex ltRegex = new LTRegex();
100 internal readonly static Regex serverTagsRegex = new ServerTagsRegex();
101 internal readonly static Regex runatServerRegex = new RunatServerRegex();
104 * Turns relative virtual path into absolute ones
106 internal VirtualPath ResolveVirtualPath(VirtualPath virtualPath) {
107 return VirtualPathProvider.CombineVirtualPathsInternal(CurrentVirtualPath, virtualPath);
110 private bool IsVersion40OrAbove() {
111 if (HostingEnvironment.IsHosted) {
112 // If we are running in a hosted environment, then we can simply check the target version.
113 return MultiTargetingUtil.IsTargetFramework40OrAbove;
116 // Otherwise, we are in the designer, and thus should check using the type description provider.
117 // The new type TagRegex35 only exists when targeting 4.0 and above.
118 return TargetFrameworkUtil.IsSupportedType(typeof(TagRegex35));
122 internal Regex TagRegex {
124 if (_tagRegex == null) {
125 _tagRegex = IsVersion40OrAbove() ? tagRegex40 : tagRegex35;