标签:style blog color os art for
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Diagnostics; namespace ExtensionMethodDump { class Program { static void Main(string[] args) { var song = new { Artist = "Jussi Bjorling", Song = "Aida" }; song.Dump(); Console.ReadLine(); } } public static class Dumper { public static void Dump(this Object o) { PropertyInfo[] properties = o.GetType().GetProperties(); foreach (PropertyInfo p in properties) { try { Console.WriteLine(string.Format("Name: {0}, Value: {1}", p.Name, p.GetValue(o, null))); } catch { Console.WriteLine(string.Format("Name: {0}, Value: {1}", p.Name, "unk.")); } } } } }
标签:style blog color os art for
原文地址:http://www.cnblogs.com/swtool/p/3840297.html