Exemple #1
0
        public PropertyChangeWatcher AddWatcher(IList <string> propertyNames, Action handler)
        {
            Contract.Requires(handler != null);
            Contract.Requires(propertyNames != null);
            Contract.Requires(propertyNames.Count > 0);
            Contract.Requires(propertyNames.AllUnique());
            BotUtil.ThrowUnless(propertyNames.All(name => OwnerType.HasPublicInstanceProperty(name)), "The target object does not contain one or more of the properties provided");

            lock (_handlers)
            {
                foreach (var key in propertyNames)
                {
                    BotUtil.ThrowUnless <ArgumentException>(!IsWatching(key), "Must not already be watching property '{0}'".StringFormat(key));
                }

                if (_handlers.Count == 0)
                {
                    _owner.PropertyChanged += _owner_PropertyChanged;
                }

                foreach (var propertyName in propertyNames)
                {
                    _handlers[propertyName] = handler;
                }
                return(this);
            }
        }
Exemple #2
0
 public void StopWatching(string property)
 {
     lock (_handlers)
     {
         BotUtil.ThrowUnless(IsWatching(property));
         _handlers.Remove(property);
         if (_handlers.Count == 0)
         {
             _owner.PropertyChanged -= _owner_PropertyChanged;
         }
     }
 }
 public static void Requires <TException>(bool truth, string message) where TException : Exception
 {
     BotUtil.ThrowUnless <TException>(truth, message);
 }
 public static void Requires <TException>(bool truth) where TException : Exception, new()
 {
     BotUtil.ThrowUnless <TException>(truth);
 }
 public static void Requires(bool truth, string message = null)
 {
     BotUtil.ThrowUnless(truth, message);
 }