using Study.DelegateSeries.Core.Calculator;
using System;

namespace Study.DelegateSeries.Core
{
    /// <summary>
    /// 委托学习
    /// 使用:定义委托、实例化委托、调用委托
    /// </summary>
    public class StudyDelegate
    {
        /*
         * 委托系列学习
         * 1、委托概念
         * 2、定义与使用委托
         * 3、多播委托
         * 4、使用匿名方法
         * 5、使用Lamda表达式
         * 6、委托使用场景
         * 7、委托与事件
         * 8、委托与接口
         * 9、其它
         * 10、总结
         */

        #region 定义委托,DeclareDelegate类
        #endregion

        #region 实例化委托

        /// <summary>
        /// 基础语法
        /// (c#1.0 开始提供)
        /// </summary>
        public CalculatorDelegate BaseInstance()
        {
            CalculatorDelegate operation = new CalculatorDelegate(new Addition().Add);
            return operation;
        }

        /// <summary>
        /// c#2.0 简写方法
        /// (基于类型推断)
        /// </summary>
        public CalculatorDelegate AutoTypeInstance()
        {
            CalculatorDelegate operation = new Subtraction().Difference;
            return operation;
        }

        /// <summary>
        /// c#2.0 匿名委托
        /// (使用匿名方法实例化的委托)
        /// </summary>
        public CalculatorDelegate AnonymousInstance()
        {
            //c# 2.0基础语法
            CalculatorDelegate operation = delegate (decimal a,decimal b) { return (a * b) * (a * b); };
            return operation;
        }

        /// <summary>
        /// c#3.0 Lambda表达式
        /// (实质:"Lambda表达式"是一个匿名函数)
        /// </summary>
        public CalculatorDelegate LambdaInstance()
        {
            CalculatorDelegate operation = (decimal a,decimal b)=> { return a * a + b * b + 2 * a * b; };
            //自动推断
            CalculatorDelegate operation2 = (a,b) => { return a * a + b * b + 2 * a * b; };

            //{}只有一句时的简写
            CalculatorDelegate operation3 = (a, b) => a * a + b * b + 2 * a * b ;

            return operation;
        }

        #endregion

        #region 调用委托
        #endregion

        #region 闭包
        #endregion

        #region 多播委托
        #endregion

        #region 泛型委托
        #endregion

        #region 内置委托
        #endregion

        #region 委托与事件
        #endregion

        #region 委托与接口
        #endregion
    }
}