Пример #1
0
        private void LoadFields(XElement element, IModelDefinition modelDefinition, IModelValueSetter setter)
        {
            foreach (IFieldDefinition fieldDefinition in modelDefinition.Fields)
            {
                if (fieldDefinition.Metadata.Get("IsPersistent", true))
                {
                    string rawValue = null;
                    if (fieldDefinition.Metadata.Get("IsXmlElementContent", false))
                    {
                        rawValue = element.Value;
                    }
                    else
                    {
                        rawValue = element.Attribute(fieldDefinition.Identifier)?.Value;
                    }

                    if (rawValue != null)
                    {
                        rawValue = rawValue.Trim();
                        if (converters.TryConvert(typeof(string), fieldDefinition.FieldType, rawValue, out object value))
                        {
                            setter.TrySetValue(fieldDefinition.Identifier, value);
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Sets values to <paramref name="targetSetter"/> from <paramref name="sourceGetters"/>.
        /// </summary>
        /// <param name="targetSetter">Target.</param>
        /// <param name="sourceGetters">Sources.</param>
        public void Update(IModelValueSetter targetSetter, params IModelValueGetter[] sourceGetters)
        {
            foreach (IFieldDefinition field in ModelDefinition.Fields)
            {
                object value;
                foreach (IModelValueGetter sourceGetter in sourceGetters)
                {
                    if (sourceGetter.TryGetValue(field.Identifier, out value))
                    {
                        if (IsAutoConversion && !IsAssignable(field.FieldType, value))
                        {
                            value = Converts.To(field.FieldType, value);
                        }

                        targetSetter.TrySetValue(field.Identifier, value);
                    }
                }
            }
        }
 /// <summary>
 /// Creates new instance that wraps <paramref name="innerSetter"/> and raises <see cref="INotifyPropertyChanged.PropertyChanged"/>.
 /// </summary>
 /// <param name="innerSetter">Inner setter.</param>
 public ObservableModelValueSetter(IModelValueSetter innerSetter)
 {
     Ensure.NotNull(innerSetter, "innerSetter");
     this.innerSetter = innerSetter;
 }