Created
September 22, 2011 13:29
-
-
Save grumpydev/1234767 to your computer and use it in GitHub Desktop.
Small class to work around AppDomain not existing in WinRT - allows enumeration of assemblies in the package -http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/6e8d015b-4c3b-4e1a-9884-d986ba5935c0/
This file contains 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
private sealed class AppDomain | |
{ | |
public static AppDomain CurrentDomain { get; private set; } | |
static AppDomain() | |
{ | |
CurrentDomain = new AppDomain(); | |
} | |
public Assembly[] GetAssemblies() | |
{ | |
return GetAssemblyListAsync().Result.ToArray(); | |
} | |
private async System.Threading.Tasks.Task<IEnumerable<Assembly>> GetAssemblyListAsync() | |
{ | |
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation; | |
List<Assembly> assemblies = new List<Assembly>(); | |
foreach (Windows.Storage.StorageFile file in await folder.GetFilesAsync()) | |
{ | |
if (file.FileType == ".dll" || file.FileType == ".exe") | |
{ | |
AssemblyName name = new AssemblyName() { Name = file.Name }; | |
Assembly asm = Assembly.Load(name); | |
assemblies.Add(asm); | |
} | |
} | |
return assemblies; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better write
AssemblyName name = new AssemblyName() { Name = Path.GetFileNameWithoutExtension(file.Name) };
at line 24