■ Assembly 클래스 : 참조 어셈블리 나열하기

----------------------------------------------------------------------------------------------------

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

}

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker