201807022222->关于Action拓展

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


/*
 * action 链式拓展
 * 实际运用中只需
 * action.Execute传入参数即可
 * 在外部可以省下空判定的语句了
 * 写空判定写到我烦了
 */


public static class ActionEx
{
    public static Action Execute(this Action src)
    {
        if (src != null)
        {
            src();
        }
        return src;
    }


    public static Action<T> Execute<T>(this Action<T> src, T args1)
    {
        if (src != null)
        {
            src(args1);
        }
        return src;
    }


    public static Action<T, T1> Execute<T, T1>(this Action<T, T1> src, T args1, T1 args2)
    {
        if (src != null)
        {
            src(args1, args2);
        }
        return src;
    }


    public static Action<T, T1, T2> Execute<T, T1, T2>(this Action<T, T1, T2> src, T args1, T1 args2, T2 args3)
    {
        if (src != null)
        {
            src(args1, args2, args3);
        }
        return src;
    }


    public static Action<T, T1, T2, T3> Execute<T, T1, T2, T3>(this Action<T, T1, T2, T3> src, T args1, T1 args2, T2 args3, T3 args4)
    {
        if (src != null)
        {
            src(args1, args2, args3, args4);
        }
        return src;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_28902031/article/details/80890827