Skip to content

Instantly share code, notes, and snippets.

@sliekens
Last active July 25, 2016 13:47
Show Gist options
  • Save sliekens/eae0c33733b4cadd652de5e3e618d322 to your computer and use it in GitHub Desktop.
Save sliekens/eae0c33733b4cadd652de5e3e618d322 to your computer and use it in GitHub Desktop.
using System;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Optimization;
[DebuggerStepThrough]
public static class BundleCollectionExtensions
{
public static void VerifyStyleBundles(this BundleCollection instance)
{
foreach (var bundle in instance.OfType<StyleBundle>())
{
var bundleVirtualDirectory = bundle.Path.Substring(0, bundle.Path.LastIndexOf(@"/"));
foreach (var file in bundle.EnumerateFiles(new BundleContext(new EmptyHttpContext(), instance, "~")))
{
var fileVirtualDirectory = file.IncludedVirtualPath.Substring(
0,
file.IncludedVirtualPath.LastIndexOf(@"/"));
if (fileVirtualDirectory != bundleVirtualDirectory)
{
throw new InvalidOperationException(
string.Format(
"Bundle '{0}' includes a file in a different location: '{1}'.",
bundle.Path,
file.IncludedVirtualPath));
}
}
}
}
private class EmptyHttpContext : HttpContextBase
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment