Esempio n. 1
0
        public void CopyTo(IDictionaryAdapter other, Func <PropertyDescriptor, bool> selector)
        {
            if (ReferenceEquals(this, other))
            {
                return;
            }

            if (other.Meta.Type.IsAssignableFrom(Meta.Type) == false)
            {
                throw new ArgumentException(string.Format(
                                                "Unable to copy to {0}.  The type must be assignable from {1}.",
                                                other.Meta.Type.FullName, Meta.Type.FullName));
            }

            if (This.CopyStrategies.Aggregate(false, (copied, s) => copied | s.Copy(this, other, ref selector)))
            {
                return;
            }

            selector = selector ?? (property => true);

            foreach (var property in This.Properties.Values.Where(property => selector(property)))
            {
                var propertyValue = GetProperty(property.PropertyName, true);
                other.SetProperty(property.PropertyName, ref propertyValue);
            }
        }
Esempio n. 2
0
        public void CopyTo(IDictionaryAdapter other, Predicate <PropertyDescriptor> selector)
        {
            if (Meta.Type.IsAssignableFrom(other.Meta.Type) == false)
            {
                throw new ArgumentException(string.Format(
                                                "Unable to copy to {0}.  The type must be assignable from {1}.",
                                                other.Meta.Type.FullName, Meta.Type.FullName));
            }

            if (This.CopyStrategy != null)
            {
                This.CopyStrategy.Copy(this, other, selector);
                return;
            }

            selector = selector ?? (p => true);

            foreach (var property in This.Properties.Values.Where(p => selector(p)))
            {
                var propertyValue = GetProperty(property.PropertyName, true);
                if (propertyValue != null)
                {
                    other.SetProperty(property.PropertyName, ref propertyValue);
                }
            }
        }
		public void CopyTo(IDictionaryAdapter other, Func<PropertyDescriptor, bool> selector)
		{
			if (ReferenceEquals(this, other))
			{
				return;
			}

			if (other.Meta.Type.IsAssignableFrom(Meta.Type) == false)
			{
				throw new ArgumentException(string.Format(
					"Unable to copy to {0}.  The type must be assignable from {1}.",
					other.Meta.Type.FullName, Meta.Type.FullName));
			}

			if (This.CopyStrategies.Aggregate(false, (copied, s) => copied | s.Copy(this, other, ref selector)))
			{
				return;
			}

			selector = selector ?? (property => true);

			foreach (var property in This.Properties.Values.Where(property => selector(property)))
			{
				var propertyValue = GetProperty(property.PropertyName, true);
				other.SetProperty(property.PropertyName, ref propertyValue);
			}
		}
Esempio n. 4
0
        private void HandleListChanged(object value, ListChangedEventArgs args, IDictionaryAdapter dictionaryAdapter, PropertyDescriptor property)
        {
            var change = args.ListChangedType;
            var changed
                = change == ListChangedType.ItemAdded ||
                  change == ListChangedType.ItemDeleted ||
                  change == ListChangedType.ItemMoved ||
                  change == ListChangedType.Reset;

            if (changed && dictionaryAdapter.ShouldClearProperty(property, value))
            {
                value = null;
                dictionaryAdapter.SetProperty(property.PropertyName, ref value);
            }
        }
		public void CopyTo(IDictionaryAdapter other, Predicate<PropertyDescriptor> selector)
		{
			if (Meta.Type.IsAssignableFrom(other.Meta.Type) == false)
			{
				throw new ArgumentException(string.Format(
					"Unable to copy to {0}.  The type must be assignable from {1}.",
					other.Meta.Type.FullName, Meta.Type.FullName));
			}

			if (This.CopyStrategy != null && This.CopyStrategy.Copy(this, other, ref selector))
			{
				return;
			}

			selector = selector ?? (p => true);

			foreach (var property in This.Properties.Values.Where(p => selector(p)))
			{
				var propertyValue = GetProperty(property.PropertyName, true);
				other.SetProperty(property.PropertyName, ref propertyValue);
			}
		}