Esempio n. 1
0
        public void RegisterObserver(IOperationObserver observer, List <OperationType> types)
        {
            if (observer == null)
            {
                return;
            }

            if (null == types)
            {
                return;
            }

            ObserverItem observerItem = null;

            foreach (var type in types)
            {
                observerItem = new ObserverItem(observer, type);
                if (!observerItems.Contains(observerItem))
                {
                    observerItems.Add(observerItem);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 不传type时对 observer进行检查,实现了几种接口就监听几种
        /// 传入type时 只监听对应接口
        /// </summary>
        /// <param name="observer"></param>
        /// <param name="type"></param>
        public void RegisterObserver(IOperationObserver observer, OperationType type0, OperationType type1 = OperationType.Default, OperationType type2 = OperationType.Default)
        {
            if (observer == null)
            {
                return;
            }

            if (type0.Equals(OperationType.Default))
            {
                return;
            }

            var observerItem = new ObserverItem(observer, type0);

            if (!observerItems.Contains(observerItem))
            {
                observerItems.Add(observerItem);
            }

            if (!type1.Equals(OperationType.Default))
            {
                observerItem = new ObserverItem(observer, type1);
                if (!observerItems.Contains(observerItem))
                {
                    observerItems.Add(observerItem);
                }
            }

            if (!type2.Equals(OperationType.Default))
            {
                observerItem = new ObserverItem(observer, type2);
                if (!observerItems.Contains(observerItem))
                {
                    observerItems.Add(observerItem);
                }
            }
        }