Last active
July 25, 2016 13:47
-
-
Save sliekens/eae0c33733b4cadd652de5e3e618d322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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