첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ SystemParam.cs

namespace TestProject
{
    /// <summary>
    /// 시스템 매개 변수
    /// </summary>
    public class SystemParam
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 명칭
        /// </summary>
        private string name;

        /// <summary>
        /// 값
        /// </summary>
        private object value;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 명칭 - Name

        /// <summary>
        /// 명칭
        /// </summary>
        public string Name
        {
            set
            {
                this.name = value;
            }
            get
            {
                return this.name;
            }
        }

        #endregion
        #region 값 - Value

        /// <summary>
        /// 값
        /// </summary>
        public object Value
        {
            set
            {
                this.value = value;
            }
            get
            {
                return this.value;
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 문자열 구하기 - ToString()

        /// <summary>
        /// 문자열 구하기
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Name + " = " + Value;
        }

        #endregion
    }
}

 

728x90

 

▶ PropertyInfoComparer.cs

using System.Collections.Generic;
using System.Reflection;

namespace TestProject
{
    /// <summary>
    /// 속성 정보 비교자
    /// </summary>
    public class PropertyInfoComparer : IComparer<PropertyInfo>
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 비교하기 - Compare(source1, source2)

        /// <summary>
        /// 비교하기
        /// </summary>
        /// <param name="source1">소스 속성 정보 1</param>
        /// <param name="source2">소스 속성 정보 2</param>
        /// <returns>처리 결과</returns>
        public int Compare(PropertyInfo source1, PropertyInfo source2)
        {
            return string.Compare(source1.Name, source2.Name);
        }

        #endregion
    }
}

 

300x250

 

▶ MainWindow.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            Width      = 800;
            Height     = 600;
            Title      = "시스템 매개 변수 조회하기";
            FontFamily = new FontFamily("나눔고딕코딩");
            FontSize   = 16;

            ListView listView = new ListView();

            Content = listView;

            GridView gridView = new GridView();

            listView.View = gridView;

            GridViewColumn nameGridViewColumn = new GridViewColumn();

            nameGridViewColumn.Header               = "Property Name";
            nameGridViewColumn.Width                = 200;
            nameGridViewColumn.DisplayMemberBinding = new Binding("Name");

            gridView.Columns.Add(nameGridViewColumn);

            GridViewColumn valueViewColumn = new GridViewColumn();

            valueViewColumn.Header               = "Value";
            valueViewColumn.Width                = 200;
            valueViewColumn.DisplayMemberBinding = new Binding("Value");

            gridView.Columns.Add(valueViewColumn);

            PropertyInfo[] propertyInfoArray = typeof(SystemParameters).GetProperties();

            #region 방법 1

            Array.Sort(propertyInfoArray, new PropertyInfoComparer());
            
            foreach(PropertyInfo propertyInfo in propertyInfoArray)
            {
                if(propertyInfo.PropertyType != typeof(ResourceKey))
                {
                    SystemParam systemParam = new SystemParam();
            
                    systemParam.Name  = propertyInfo.Name;
                    systemParam.Value = propertyInfo.GetValue(null, null);
            
                    listView.Items.Add(systemParam);
                }
            }

            #endregion
            #region 방법 2

            //foreach(PropertyInfo propertyInfo in propertyInfoArray)
            //{
            //    if(propertyInfo.PropertyType != typeof(ResourceKey))
            //    {
            //        SystemParam systemParam = new SystemParam();
            //
            //        systemParam.Name  = propertyInfo.Name;
            //        systemParam.Value = propertyInfo.GetValue(null, null);
            //
            //        listView.Items.Add(systemParam);
            //    }
            //}
            //
            //listView.Items.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

            #endregion
            #region 방법 3

            //SortedList<string, SystemParam> sortedList = new SortedList<string, SystemParam>();
            //
            //foreach(PropertyInfo propertyInfo in propertyInfoArray)
            //{
            //    if(propertyInfo.PropertyType != typeof(ResourceKey))
            //    {
            //        SystemParam systemParam = new SystemParam();
            //
            //        systemParam.Name  = propertyInfo.Name;
            //        systemParam.Value = propertyInfo.GetValue(null, null);
            //
            //        sortedList.Add(propertyInfo.Name, systemParam);
            //    }
            //}
            //
            //listView.ItemsSource = sortedList.Values;

            #endregion
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        [STAThread]
        public static void Main()
        {
            Application application = new Application();

            application.Run(new MainWindow());
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요