Example #1
0
        /// <summary>
        /// Parameter가 있는 첫번째 Constructor의 정보를 리턴함.
        /// </summary>
        /// <param name="TypeOfClass">Class의 형식</param>
        /// <param name="aTypeIs">각 Parameter의 Type</param>
        /// <param name="aDescriptionIs">각 Parameter의 Description(없으면 Name)</param>
        /// <returns>Parameter가 있는 Constructor가 없으면 false를 리턴하고, 아니면 true를 리턴함.</returns>
        /// <example>
        /// 다음은 ConTest 클래스의 Constructor 정보를 출력합니다.
        /// <code>
        /// List&lt;Type&gt; aTypeIs;
        /// List&lt;string&gt; aNameIs;
        /// List&lt;string&gt; aDescriptionIs;
        ///
        /// if (GetFirstConstructorParamInfo(typeof(ConTest), out aTypeIs, out aNameIs, out aDescriptionIs))
        /// {
        ///	 for (int i = 0; i &lt; aTypeIs.Count; i++)
        ///	 {
        ///		 Console.WriteLine("Type: {0}, Name: {1}, Description: {2}",  aTypeIs[i].ToString(), aNameIs[i], aDescriptionIs[i]);
        ///	 }
        /// }
        ///
        /// public class ConTest
        /// {
        ///     public ConTest()
        ///     {
        ///     }
        ///     public ConTest(
        ///         [Description("숫자")]
        ///         int i,
        ///         [Description("문자열 이야")]
        ///         string s,
        ///         [Description("개체(Object)")]
        ///         object o)
        ///     {
        ///
        ///     }
        /// }
        /// </code>
        /// </example>
        public static bool GetFirstConstructorParamInfo(Type TypeOfClass,
                                                        out List <Type> aTypeIs, out List <string> aNameIs, out List <string> aDescriptionIs)
        {
            aTypeIs        = new List <Type>();
            aNameIs        = new List <string>();
            aDescriptionIs = new List <string>();

            ConstructorInfo[] aConstInfo = TypeOfClass.GetConstructors();
            ParameterInfo[]   aPInfo     = null;
            foreach (ConstructorInfo Info in aConstInfo)
            {
                aPInfo = Info.GetParameters();
                if (aPInfo.Length > 0)
                {
                    break;
                }
            }

            if (aPInfo.Length == 0)
            {
                return(false);
            }

            foreach (ParameterInfo PInfo in aPInfo)
            {
                aTypeIs.Add(PInfo.ParameterType);
                aNameIs.Add(PInfo.Name);

                DescriptionAttribute[] aAttr = (DescriptionAttribute[])PInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
                string Description           = (aAttr.Length > 0) ? aAttr[0].Description : PInfo.Name;

                aDescriptionIs.Add(Description);
            }

            return(true);
        }