Bundling.Extensions.Handlers.BundleHttpHandler.GetSingleFileBundleResponse C# (CSharp) Method

GetSingleFileBundleResponse() private method

private GetSingleFileBundleResponse ( Bundle bundle, BundleContext bundleContext, string filepath ) : BundleResponse
bundle Bundle
bundleContext BundleContext
filepath string
return BundleResponse
		private BundleResponse GetSingleFileBundleResponse(Bundle bundle, BundleContext bundleContext, string filepath)
		{
			var files = bundle.EnumerateFiles(bundleContext);
			var file = files.FirstOrDefault(f => f.VirtualFile.VirtualPath.TrimStart(new[] { '/' }) == filepath);

			if (file == null)
			{
				throw new FileNotFoundException(string.Format("File not found '{0}'", filepath));
			}

			string contents;
			var virtualPathProvider = HostingEnvironment.VirtualPathProvider;
			var virtualFile = virtualPathProvider.GetFile(VirtualPathUtility.ToAppRelative(file.VirtualFile.VirtualPath));
			using (var streamReader = new StreamReader(virtualFile.Open()))
			{
				contents = streamReader.ReadToEnd();
			}

			return bundle.ApplyTransforms(bundleContext, contents, new List<BundleFile> { file });
		}