Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 public void StopWatching(string property)
 {
     lock (_handlers)
     {
         BotUtil.ThrowUnless(IsWatching(property));
         _handlers.Remove(property);
         if (_handlers.Count == 0)
         {
             _owner.PropertyChanged -= _owner_PropertyChanged;
         }
     }
 }
Ejemplo n.º 3
0
 public static void Requires <TException>(bool truth, string message) where TException : Exception
 {
     BotUtil.ThrowUnless <TException>(truth, message);
 }
Ejemplo n.º 4
0
 public static void Requires <TException>(bool truth) where TException : Exception, new()
 {
     BotUtil.ThrowUnless <TException>(truth);
 }
Ejemplo n.º 5
0
 public static void Requires(bool truth, string message = null)
 {
     BotUtil.ThrowUnless(truth, message);
 }