首页 > 代码库 > winform中获取Properties窗口的值.
winform中获取Properties窗口的值.
我写这个工具,主要是多次在将自己的代码和别人代码做对比时,不想繁琐地用眼看他设置的和自己设置的哪里不一样.
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace Properties { 7 class Properties { 8 /// <summary> 9 /// 通过类型和对象获取对象键-值的字典集合.10 /// </summary>11 /// <param name="t"></param>12 /// <param name="obj"></param>13 /// <returns></returns>14 public static Dictionary<string, string> GetProperties(Type t, object obj) {15 Dictionary<string, string> dic = new Dictionary<string, string>();16 string k, v;17 foreach (System.Reflection.PropertyInfo pInfo in t.GetProperties()) {18 try {19 //this.LayoutEngine = null;20 object[] attibutes = pInfo.GetCustomAttributes(typeof(System.ComponentModel.BrowsableAttribute), true);21 if (attibutes.Length <= 0) continue;22 k = pInfo.Name;23 v = pInfo.GetValue(obj, null) + "";24 dic.Add(k, v);25 }26 catch (System.Exception ex) {27 //todo:28 }29 }30 31 return dic;32 }33 34 /// <summary>35 /// 将GetProperties所得的键-值写入指定的文件中.36 /// </summary>37 /// <param name="dic"></param>38 /// <param name="fullFileName"></param>39 public static void SaveToFile(Dictionary<string, string> dic, string fullFileName) {40 try {41 StringBuilder sb = new StringBuilder();42 foreach (KeyValuePair<string, string> kv in dic) {43 sb.Append(kv.Key).Append(": ").AppendLine(kv.Value);44 }45 System.IO.File.WriteAllText(fullFileName, sb.ToString());46 }47 catch (System.Exception ex) {48 throw new ArgumentException(ex.Message);49 }50 }51 }52 }
winform中获取Properties窗口的值.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。