Events

CSharp · Console

/Program.cs

using System;
					
    public class Program
    {
        public static void Main(string[] args)
        {
            var a = new Animation();

            var waitForDelegate = new WaitForDelegate<IAnimation>(a);

            a.CallEnd();
        }

    }

    public interface IAnimation
    {
        event Action OnEnd;
    }

    public class Animation : IAnimation
    {
        public event Action OnEnd;

        public void CallEnd()
        {
            OnEnd();
        }
    }


    public class WaitForDelegate<T> where T : IAnimation
    {
        public WaitForDelegate(T animation)
        {
            animation.OnEnd += () => { Console.WriteLine("trigger"); };
        }
    }
;