Last active
January 1, 2016 15:49
-
-
Save JohanLarsson/8166677 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
| public static class Gac | |
| { | |
| /// <summary> | |
| /// | |
| /// </summary> | |
| /// <param name="pattern">Default search pattern "*interop*.dll"</param> | |
| /// <returns></returns> | |
| public static IEnumerable<FileInfo> InteropDlls(string pattern = "*interop*.dll") | |
| { | |
| var gac = AllFiles(new DirectoryInfo(@"C:\Windows\Assembly"), pattern) | |
| .OrderBy(x => x.Name) | |
| .AsEnumerable(); | |
| return gac; | |
| } | |
| public static IEnumerable<Assembly> InteropAssemblies(string pattern = "*interop*.dll") | |
| { | |
| var dlls = InteropDlls(pattern); | |
| var assemblies = new List<Assembly>(); | |
| foreach (var fileInfo in dlls) | |
| { | |
| try | |
| { | |
| Assembly assembly = Assembly.LoadFile(fileInfo.FullName); | |
| assemblies.Add(assembly); | |
| } | |
| catch (Exception e) | |
| { | |
| Debug.WriteLine("Error loading assembly {0} {1}",fileInfo.FullName, e.Message); | |
| } | |
| } | |
| return assemblies; | |
| } | |
| private static IEnumerable<FileInfo> AllFiles(DirectoryInfo dir, string searchPattern, IList<FileInfo> files = null) | |
| { | |
| if (files == null) | |
| files = new List<FileInfo>(); | |
| try | |
| { | |
| foreach (FileInfo f in dir.GetFiles(searchPattern)) | |
| { | |
| files.Add(f); | |
| } | |
| } | |
| catch(Exception e) | |
| { | |
| Debug.WriteLine("Error reading directory {0} {1}",dir.FullName, e.Message); | |
| return files; | |
| } | |
| foreach (DirectoryInfo d in dir.GetDirectories()) | |
| { | |
| AllFiles(d, searchPattern, files); | |
| } | |
| return files; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment