Ejemplo n.º 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);
                        }
                    }
                }
            }
        }
        public virtual bool TrySetValue(string identifier, object value)
        {
            if (innerSetter.TrySetValue(identifier, value))
            {
                RaisePropertyChanged(identifier);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
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);
                    }
                }
            }
        }