■ 시스템 매개 변수를 조회하는 방법을 보여준다.
▶ SystemParam.cs
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 80 81 82 83 |
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 } } |
▶ PropertyInfoComparer.cs
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 |
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 } } |
▶ MainWindow.cs
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
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 } } |