Пример #1
0
 public void Set(IModelFieldValue value)
 {
     foreach (var element in _elements)
     {
         FieldFactory.Create(new[] { element }).Set(value);
     }
 }
Пример #2
0
        public object Get(IModelFieldType fieldType)
        {
            var values = _elements
                         .Select(e => FieldFactory.Create(new[] { e }).Get(new ModelFieldType(fieldType.BaseType, fieldType.Format)))
                         .Where(e => e != null);

            if (fieldType.HasMultipleValues)
            {
                return(fieldType.Cast(values));
            }

            return(values.FirstOrDefault() ?? fieldType.DefaultValue);
        }
Пример #3
0
        public object Get(IModelFieldType fieldType)
        {
            var values = _elements
                         .Select(e => FieldFactory.Create(new[] { e }).Get(new ModelFieldType(fieldType.BaseType, fieldType.Format)))
                         .Where(e => e != null)
                         .ToArray();

            if (fieldType.IsFlagsEnum)
            {
                if (values.Length == 1)
                {
                    return(values.First());
                }
                return(fieldType.GetValueFromStrings(values.Select(v => v.ToString())));
            }

            if (fieldType.IsEnumerable)
            {
                return(fieldType.Cast(values));
            }

            return(values.FirstOrDefault() ?? fieldType.DefaultValue);
        }