■ Assembly 클래스를 사용해 참조 어셈블리를 나열하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
using System; using System.Collections; using System.Reflection; public class ReportReferencedAssembly { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main(argumentArray) /// <summary> /// 프로그램 시작하기 /// </summary> /// <param name="argumentArray">인자 배열</param> private static void Main(string[] argumentArray) { try { if(argumentArray.Length == 0) { Console.WriteLine("사용법 : ReportReferencedAssembly <assembly1> [assembly2 ...]"); } Hashtable assemblyHashtable = new Hashtable(); foreach(string argument in argumentArray) { Assembly assembly = Assembly.LoadFrom(argument); Report(assembly, assemblyHashtable, 0); } } catch(Exception exception) { Console.WriteLine("에러 : {0}", exception.Message); } } #endregion #region 보고하기 - Report(sourceAssembly, assemblyHashtable, indentLevel) /// <summary> /// 보고하기 /// </summary> /// <param name="sourceAssembly">소스 어셈블리</param> /// <param name="assemblyHashtable">어셈블리 해시 테이블</param> /// <param name="indentLevel">들어쓰기 레벨</param> static void Report(Assembly sourceAssembly, Hashtable assemblyHashtable, int indentLevel) { Console.Write(new string(' ', indentLevel)); AssemblyName sourceAssemblyName = sourceAssembly.GetName(); if(assemblyHashtable.Contains(sourceAssemblyName.FullName)) { Console.WriteLine("[{0}]", sourceAssemblyName.Name); return; } assemblyHashtable[sourceAssemblyName.FullName] = sourceAssemblyName.FullName; Console.WriteLine(sourceAssemblyName.Name); foreach(AssemblyName referenceAssemblyName in sourceAssembly.GetReferencedAssemblies()) { Assembly referenceAssembly = Assembly.Load(referenceAssemblyName); Report(referenceAssembly, assemblyHashtable, indentLevel + 2); } } #endregion } |