Exemplo n.º 1
0
        public ItemValues(BaseItemsViewModel vmItems)
        {
            _schema = vmItems.Schema;

            foreach (var property in _schema.GetCustomType().GetProperties())
            {
                ItemAttribute newValue = new ItemAttribute(property.Name, null);
                _valuesDictionary.Add(property.Name, newValue);
                _valuesCollection.Add(newValue);
            }
        }
Exemplo n.º 2
0
        public bool SetPropertyValue(string propertyName, object value)
        {
            String alias = _schema.NameToAlias(propertyName);

            // try to find by name if no alias is defined
            if (alias == null)
            {
                alias = propertyName;
            }

            CustomPropertyInfoHelper propertyInfo = _schema.CustomProperties.FirstOrDefault(prop => prop.Name == alias);

            if (propertyInfo == null)
            {
                return(false);
            }

            // allow adding types on the fly
            //if (propertyInfo == null || !_customPropertyValues.ContainsKey(alias))
            //  throw new Exception("There is no property with the name " + alias);

            object convertedValue = value;

            if (!ValidateValueType(value, propertyInfo._type))
            {
                convertedValue = Helper.ConvertValue(value, propertyInfo.Field.Type);
            }

            if (!_valuesDictionary.ContainsKey(alias))
            {
                // allow adding types on the fly
                ItemAttribute newValue = new ItemAttribute(alias, convertedValue);
                _valuesDictionary.Add(alias, newValue);
                _valuesCollection.Add(newValue);
                RaisePropertyChanged(alias);
            }
            else
            {
                ItemAttribute currentValue = _valuesDictionary[alias];
                if (currentValue.Value != (object)value) //TODO - consider comparing by ToString() values instead
                {
                    currentValue.Value = convertedValue;
                    RaisePropertyChanged(alias);
                }
            }

            return(true);
        }