Created
May 5, 2010 22:31
-
-
Save cstrahan/391544 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.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
using System.Threading; | |
public class ResourceInspector | |
{ | |
public delegate void FileListCallback(Stream xapFileStream); | |
public IDictionary<String, Uri> Inspect(Assembly assembly) | |
{ | |
if (assembly == null) | |
{ | |
throw new ArgumentNullException("assembly"); | |
} | |
var uriLookup = new Dictionary<string, Uri>(StringComparer.OrdinalIgnoreCase); | |
var asmName = assembly.FullName.Split(new [] { ',' })[0]; // Can't use assembly.GetName().Name in SL . . . | |
var resourceNames = | |
assembly.GetManifestResourceNames().Select( | |
name => name.Replace(".resources", "")); | |
var resourceManagers = resourceNames.Select(name => new System.Resources.ResourceManager(name, assembly)); | |
foreach (var resourceManager in resourceManagers) | |
{ | |
var dummy = resourceManager.GetStream("__dummy__"); // Need to do this, otherwise next line will fail... | |
var rs = resourceManager.GetResourceSet(Thread.CurrentThread.CurrentUICulture, false, true); | |
IDictionaryEnumerator enumerator = rs.GetEnumerator(); | |
while (enumerator.MoveNext()) | |
{ | |
// We can also do this: | |
// var stream = (Stream)enumerator.Value; | |
var resourceName = (string)enumerator.Key; | |
var uri = new Uri(asmName + ";component/" + resourceName , UriKind.Relative); | |
uriLookup[resourceName] = uri; | |
} | |
} | |
return uriLookup; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment