public void addObserver(System.Object target, Action<NSNotification> aSelector, string aName, System.Object sender=null){
			List<NSNotificationObserver> observers = null;
			if (!_name_observers.TryGetValue (aName, out observers)) {
				_name_observers[aName] = observers = new List<NSNotificationObserver>();		
			}
			NSNotificationObserver observer = null;
			var enumerator = observers.GetEnumerator();
			while (enumerator.MoveNext()) {
				NSNotificationObserver aObserver = enumerator.Current;
				if(aObserver.target == target){
					observer = aObserver;
				}
			}
			if (observer == null) {
				observer = new NSNotificationObserver ();
				observer.target = target;
				observer.selectorAndSenders = new List<NSNotificationSelectorAndSender> ();
				observers.Add(observer);
			} else {
				var eu = observer.selectorAndSenders.GetEnumerator();
				while (eu.MoveNext()) {
					NSNotificationSelectorAndSender selectorAndSender = eu.Current;
					NSUtils.Assert(selectorAndSender.selector != aSelector || selectorAndSender.sender != sender, 
					               "NSNotificationDelegate#addObserver : Dont' add observer with same target/method/sender !");			
				}	
			}
			NSNotificationSelectorAndSender selAndSender = new NSNotificationSelectorAndSender();
			selAndSender.selector = aSelector;
			selAndSender.sender = sender;
			observer.selectorAndSenders.Add (selAndSender);
		}
Esempio n. 2
0
        public void addObserver(System.Object target, Action <NSNotification> aSelector, string aName, System.Object sender = null)
        {
            List <NSNotificationObserver> observers = null;

            if (!_name_observers.TryGetValue(aName, out observers))
            {
                _name_observers[aName] = observers = new List <NSNotificationObserver>();
            }
            NSNotificationObserver observer = null;
            var enumerator = observers.GetEnumerator();

            while (enumerator.MoveNext())
            {
                NSNotificationObserver aObserver = enumerator.Current;
                if (aObserver.target == target)
                {
                    observer = aObserver;
                }
            }
            if (observer == null)
            {
                observer                    = new NSNotificationObserver();
                observer.target             = target;
                observer.selectorAndSenders = new List <NSNotificationSelectorAndSender> ();
                observers.Add(observer);
            }
            else
            {
                var eu = observer.selectorAndSenders.GetEnumerator();
                while (eu.MoveNext())
                {
                    NSNotificationSelectorAndSender selectorAndSender = eu.Current;
                    NSUtils.Assert(selectorAndSender.selector != aSelector || selectorAndSender.sender != sender,
                                   "NSNotificationDelegate#addObserver : Dont' add observer with same target/method/sender !");
                }
            }
            NSNotificationSelectorAndSender selAndSender = new NSNotificationSelectorAndSender();

            selAndSender.selector = aSelector;
            selAndSender.sender   = sender;
            observer.selectorAndSenders.Add(selAndSender);
        }
Esempio n. 3
0
        public void postNotification(NSNotification n)
        {
            List <NSNotificationObserver> observers = observersForName(n.name);

            if (observers == null)
            {
                return;
            }
            for (int i = observers.Count - 1; i >= 0; i--)
            {
                NSNotificationObserver observer = observers[i];
                List <NSNotificationSelectorAndSender> selectorAndSenders = observer.selectorAndSenders;
                for (int j = selectorAndSenders.Count - 1; j >= 0; j--)
                {
                    NSNotificationSelectorAndSender selectorAndSender = selectorAndSenders[j];
                    if (selectorAndSender.sender == null || selectorAndSender.sender == n.sender)
                    {
                        selectorAndSender.selector(n);
                    }
                }
            }
        }