/// <summary> /// Gets the virtual path of the source of the generated type /// </summary> /// <param name="typeName"></param> /// <returns></returns> public string GetVirtualPath(string typeName) { string virtualPath; lock (this.Cache) { // check the cache to prevent extra lookups if (this.Cache.TryGetValue(typeName, out virtualPath)) { return(virtualPath); } } // precompiled sites can bring back directly since already loaded in AppDomain Type type = BuildManager.GetType(typeName, false, false); if (type == null) { // dynamic apps compile to a temp directory foreach (string asm in Directory.GetFiles(AppDomain.CurrentDomain.DynamicDirectory, "App_Web_*.dll", SearchOption.TopDirectoryOnly)) { type = Assembly.LoadFrom(asm).GetType(typeName, false, false); if (type != null) { break; } } } // save the virtual path in cache for future lookup virtualPath = BuildPathAttribute.GetVirtualPath(type); if (String.IsNullOrEmpty(virtualPath)) { lock (this.Cache) { // mark as not found for future lookups this.Cache[typeName] = virtualPath = String.Empty; } } else { lock (this.Cache) { // apply to both just in case discrepancy this.Cache[type.FullName] = this.Cache[typeName] = virtualPath; } } return(virtualPath); }
/// <summary> /// Gets the corresponding virtual path for the source of the given generated type. /// </summary> /// <param name="type">the Type marked with VirtualPathAttribute</param> /// <returns>virtual path of the source</returns> public static string GetVirtualPath(Type type) { if (type == null) { return(null); } BuildPathAttribute attrib = Attribute.GetCustomAttribute(type, typeof(BuildPathAttribute), false) as BuildPathAttribute; if (attrib == null) { return(null); } return(attrib.VirtualPath); }