Ejemplo n.º 1
0
        public bool TryGetSourceFieldBinding(string property, out PropertyFieldBinding binding)
        {
            List <PropertyFieldBinding> bindings;

            if (!this.propertyToFieldMapping.TryGetValue(property, out bindings))
            {
                binding = null;
                return(false);
            }

            binding = bindings.SingleOrDefault(b => b.IsActive);

            return(binding != null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Finds a field that holds object returned by the property. Activates binding to that field and deactivates other bindings.
        /// </summary>
        /// <param name="args"></param>
        /// <returns>true if there is active binding, false if not.</returns>
        public bool RefreshPropertyBindings(LocationInterceptionArgs args)
        {
            bool bindingFound = false;
            PropertyFieldBinding        bindingToActivate = null;
            List <PropertyFieldBinding> sourceFields;

            if (this.TryGetSourceFieldBindings(args.LocationName, out sourceFields))
            {
                foreach (PropertyFieldBinding propertyFieldBinding in sourceFields.OrderBy(f => f.IsActive))
                {
                    object value = propertyFieldBinding.Field.GetValue(args.Instance);

                    if (this.fieldValueComparer.AreEqual(args.LocationFullName, value, args.Value))
                    {
                        // field and property values are equal, mark source field binding as active and if there is a handler hooked to the property un hook it
                        bindingFound = true;
                        if (propertyFieldBinding.IsActive)
                        {
                            break;
                        }

                        bindingToActivate = propertyFieldBinding;
                    }
                    else
                    {
                        // field and property values differ, mark source field binding as inactive and re hook a handler to the property
                        propertyFieldBinding.IsActive = false;
                    }
                }
            }

            if (bindingFound && bindingToActivate != null)
            {
                bindingToActivate.IsActive = true;
            }

            return(bindingFound);
        }