码迷,mamicode.com
首页 > 其他好文 > 详细

LinQ 定义带有返回类型的扩展方法3.2

时间:2014-07-13 23:53:33      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   art   for   

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Diagnostics;

namespace ExtensionWithReturn
{
    class Program
    {
        static void Main(string[] args)
        {
            var songs = new
            {
                Artist = "Green Day",
                Song = "Wake Me Up When September Ends"
            };
            Console.WriteLine(songs.Dump());
            Console.ReadLine();
        }
    }
    public static class Dumper
    {
        public static string Dump(this Object o)
        {
            PropertyInfo[] properties = o.GetType().GetProperties();
            StringBuilder builder = new StringBuilder();
            foreach (PropertyInfo p in properties)
            {
                try
                {
                    builder.AppendFormat(string.Format("Name: {0}, Value: {1}", p.Name, p.GetValue(o, null)));
                }
                catch
                {
                    builder.AppendFormat(string.Format("Name: {0}, Value: {1}", p.Name, "unk."));
                }
                builder.AppendLine();
            }
            return builder.ToString();
        }
    }
}

 

LinQ 定义带有返回类型的扩展方法3.2,布布扣,bubuko.com

LinQ 定义带有返回类型的扩展方法3.2

标签:style   blog   color   os   art   for   

原文地址:http://www.cnblogs.com/swtool/p/3840331.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!