internal override void AddDirective(string directive, IDictionary atts) { if (String.Compare("MasterType", directive, StringComparison.OrdinalIgnoreCase) == 0) { PageParserFilter pfilter = PageParserFilter; if (pfilter != null) { pfilter.PreprocessDirective(directive.ToLowerInvariant(), atts); } string type = GetString(atts, "TypeName", null); if (type != null) { masterType = LoadType(type); if (masterType == null) { ThrowParseException("Could not load type '" + type + "'."); } } else { string path = GetString(atts, "VirtualPath", null); if (!String.IsNullOrEmpty(path)) { var vpp = HostingEnvironment.VirtualPathProvider; if (!vpp.FileExists(path)) { ThrowParseFileNotFound(path); } path = vpp.CombineVirtualPaths(VirtualPath.Absolute, VirtualPathUtility.ToAbsolute(path)); masterTypeVirtualPath = path; AddDependency(path); } else { ThrowParseException("The MasterType directive must have either a TypeName or a VirtualPath attribute."); } } if (masterType != null) { AddAssembly(masterType.Assembly, true); } } else { base.AddDirective(directive, atts); } }
internal override void AddDirective (string directive, IDictionary atts) { bool isMasterType = String.Compare ("MasterType", directive, StringComparison.OrdinalIgnoreCase) == 0; bool isPreviousPageType = isMasterType ? false : String.Compare ("PreviousPageType", directive, StringComparison.OrdinalIgnoreCase) == 0; string typeName = null; string virtualPath = null; Type type = null; if (isMasterType || isPreviousPageType) { PageParserFilter pfilter = PageParserFilter; if (pfilter != null) pfilter.PreprocessDirective (directive.ToLowerInvariant (), atts); typeName = GetString (atts, "TypeName", null); virtualPath = GetString (atts, "VirtualPath", null); if (typeName != null && virtualPath != null) ThrowParseException ( String.Format ("The '{0}' directive must have exactly one attribute: TypeName or VirtualPath", directive)); if (typeName != null) { type = LoadType (typeName); if (type == null) ThrowParseException (String.Format ("Could not load type '{0}'.", typeName)); if (isMasterType) masterType = type; else previousPageType = type; } else if (!String.IsNullOrEmpty (virtualPath)) { if (!HostingEnvironment.VirtualPathProvider.FileExists (virtualPath)) ThrowParseFileNotFound (virtualPath); AddDependency (virtualPath); if (isMasterType) masterVirtualPath = virtualPath; else previousPageVirtualPath = virtualPath; } else ThrowParseException (String.Format ("The {0} directive must have either a TypeName or a VirtualPath attribute.", directive)); if (type != null) AddAssembly (type.Assembly, true); } else base.AddDirective (directive, atts); }