예제 #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)
                         .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);
        }