Exemplo n.º 1
0
        public IndexPropertyObserver(Type propertyContainingType, IndexPropertyPathElement propertyPathElement, XamlNamespaces namespaces)
        {
            baseObserver = CreateBaseObserver(propertyContainingType, propertyPathElement.PropertyName);

            PropertyInfo indexPropertyInfo = baseObserver != null?baseObserver.ValueType.GetDefaultIndexProperty() :
                                                 propertyPathElement.PropertyName.IsEmpty ? propertyContainingType.GetDefaultIndexProperty() : propertyContainingType.GetInstanceProperty(propertyPathElement.PropertyName.MemberName);

            if (indexPropertyInfo == null)
            {
                throw new Granular.Exception("Property \"{0}.{1}\" does not have an indexer", propertyContainingType.Name, propertyPathElement.PropertyName.MemberName);
            }

            if (indexPropertyInfo.GetIndexParameters().Count() != propertyPathElement.IndexRawValues.Count())
            {
                throw new Granular.Exception("Invalid number of index parameters for \"{0}.{1}\"", indexPropertyInfo.DeclaringType.Name, indexPropertyInfo.Name);
            }

            indexerObserver = new ClrPropertyObserver(indexPropertyInfo, propertyPathElement.ParseIndexValues(indexPropertyInfo));
            indexerObserver.ValueChanged += (sender, e) => ValueChanged.Raise(this, e);

            if (baseObserver != null)
            {
                baseObserver.ValueChanged += (sender, e) => indexerObserver.SetBaseValue(baseObserver.Value);
                indexerObserver.SetBaseValue(baseObserver.Value);
            }
        }
Exemplo n.º 2
0
 public void SetBaseValue(object baseValue)
 {
     if (baseObserver != null)
     {
         baseObserver.SetBaseValue(baseValue);
     }
     else
     {
         indexerObserver.SetBaseValue(baseValue);
     }
 }
Exemplo n.º 3
0
        private void SetDelegateObserverBaseValue()
        {
            object baseValue = baseObserver.Value;

            if (ObservableValue.IsNullOrUnset(baseValue) || baseObserverValueType == baseValue.GetType())
            {
                if (delegateObserver != null)
                {
                    delegateObserver.SetBaseValue(baseValue);
                }

                return;
            }

            baseObserverValueType = baseValue.GetType();

            if (delegateObserver is IDisposable)
            {
                ((IDisposable)delegateObserver).Dispose();
            }

            delegateObserver = propertyPathElement.CreatePropertyObserver(baseObserverValueType);

            if (delegateObserver != null)
            {
                ValueType = delegateObserver.ValueType;
                delegateObserver.SetBaseValue(baseValue);
                delegateObserver.ValueChanged += (sender, e) => observableValue.Value = delegateObserver.Value;
                observableValue.Value          = delegateObserver.Value;
            }
            else
            {
                ValueType             = null;
                observableValue.Value = ObservableValue.UnsetValue;
            }
        }
Exemplo n.º 4
0
        private void SetDelegateObserverBaseValue()
        {
            object baseValue = baseObserver.Value;

            if (ObservableValue.IsNullOrUnset(baseValue) || baseObserverValueType == baseValue.GetType())
            {
                if (delegateObserver != null)
                {
                    delegateObserver.SetBaseValue(baseValue);
                }

                return;
            }

            baseObserverValueType = baseValue.GetType();

            if (delegateObserver is IDisposable)
            {
                ((IDisposable)delegateObserver).Dispose();
            }

            delegateObserver = propertyPathElement.CreatePropertyObserver(baseObserverValueType);

            if (delegateObserver != null)
            {
                ValueType = delegateObserver.ValueType;
                delegateObserver.SetBaseValue(baseValue);
                delegateObserver.ValueChanged += (sender, e) => observableValue.Value = delegateObserver.Value;
                observableValue.Value = delegateObserver.Value;
            }
            else
            {
                ValueType = null;
                observableValue.Value = ObservableValue.UnsetValue;
            }
        }