zoukankan      html  css  js  c++  java
  • LinQ 定义带有返回类型的扩展方法3.2

    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();
            }
        }
    }
  • 相关阅读:
    ejs
    appcan.slider.js探索
    js语法重点
    canvas动画
    canvas绘图
    Bootstrap 表单
    模态框
    Node.js EventEmitter(事件队列)
    Node.js 事件循环
    react native 页面跳转
  • 原文地址:https://www.cnblogs.com/swtool/p/3840331.html
Copyright © 2011-2022 走看看