示例#1
0
        private void OnCarCreated(string car)
        {
            // C# 5
            //CarInfo handler = _carCreated;
            //if (handler != null)
            //{
            //    handler(car);
            //}

            // C# 6
            //            _carCreated?.Invoke(car);

            CarInfo handler = _carCreated;

            if (handler != null)
            {
                var invocations = handler.GetInvocationList();
                foreach (CarInfo invocation in invocations)
                {
                    try
                    {
                        invocation?.Invoke(car);
                    }
                    catch
                    {
                        // ignore
                    }
                }
            }
        }