Example #1
0
        public CompositeObjectProperty GetVirtualProperty(Type t, CompositeObjectProperty p)
        {
            if (!IsPropertyAvailable(t, p))
            {
                throw new KeyNotFoundException();
            }

            return(GetProperties(t).First(prop => prop.PropName == p.PropName));
        }
Example #2
0
        public void SetValue(CompositeObject owner,
                             CompositeObjectProperty prop,
                             IPropertyValue value)
        {
            Dictionary <CompositeObjectProperty, IPropertyValue> props;

            if (!_valueStorage.TryGetValue(owner, out props))
            {
                props = new Dictionary <CompositeObjectProperty, IPropertyValue>();
                _valueStorage.Add(owner, props);
            }

            var oldValue = props[prop];

            props[prop] = value;
            oldValue.OnDetached(owner, prop);
            value.OnAttached(owner, prop);
        }
Example #3
0
        public void RegisterProperty <TOwner>(CompositeObjectProperty property)
        {
            var t = typeof(TOwner);

            if (_registeredProperties.TryGetValue(t, out var list))
            {
                list.Add(property);
            }
            else
            {
                list = new List <CompositeObjectProperty>()
                {
                    property
                };

                _registeredProperties.Add(t, list);
            }
        }
Example #4
0
        public bool IsPropertyAvailable(Type tOwner, CompositeObjectProperty property)
        {
            bool available = _registeredProperties.TryGetValue(tOwner, out var props) &&
                             props.Contains(property);

            if (property.Metadata.Options.HasFlag(PropertyOptions.Inherits))
            {
                var t = tOwner.BaseType;
                while (!available && t is not null)
                {
                    available = _registeredProperties.TryGetValue(t, out props) &&
                                props.Contains(property);

                    t = t.BaseType;
                }
            }

            return(available);
        }
Example #5
0
 public void OnDetached(CompositeObject owner, CompositeObjectProperty prop)
 {
     Detached?.Invoke(owner, prop);
 }
Example #6
0
 public void OnChanged(CompositeObject owner, CompositeObjectProperty prop)
 {
     Changed?.Invoke(owner, prop);
 }
Example #7
0
 public bool IsSet(CompositeObject obj,
                   CompositeObjectProperty prop)
 {
     return(_valueStorage[obj][prop] is not UnsetValue);
 }
Example #8
0
 public IPropertyValue GetValue(CompositeObject owner,
                                CompositeObjectProperty prop)
 {
     return(_valueStorage[owner][prop]);
 }