FluentInterfaceDemo 草稿或者说笔记

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

namespace FluentInterfaceDemo
{
    class Program
    {
        static void Main(string[] args)
        {

            Fluent fluent = new Fluent();
            fluent.Money = 10000;
            Console.WriteLine(fluent.IsPass(f => f.Money));
            Console.WriteLine(fluent.CalcTax(f => f.Money).Money);

            Console.WriteLine(GetType<Fluent>(fluent));

            Console.Read();
        }


        static string GetType<TSource>(TSource t)
        {
            return t.GetType().ToString();

        }
    }

    class Fluent:IFluent
    {
        public int UserID { get; set; }
        public string Name { get; set; }
        public double Money { get; set; }
    }

    static class FluentExtent
    {
        public static bool IsPass(this IFluent fluent, Func<Fluent, double> func)
        {
            double m = func((Fluent)fluent);
            return double.Parse(m.ToString()) > 0;
        }

        public static Fluent CalcTax(this Fluent fluent, Func<Fluent, double> func)
        {
            fluent.Money = func(fluent) * 0.35;
            return fluent;
        }

    }

    class Tax
    {
        public double money { get; set; }
        public static double GetTax()
        {
            return 100;
        }
    }

    interface IFluent
    {

    }
}

posted @ 2013-02-18 14:33  Bruce-He  阅读(310)  评论(0编辑  收藏  举报
成都共享办公室