Пример #1
0
        public EnumValueList GetEnumValues()
        {
            if (Type != ChartParameterType.Enum)
            {
                throw new InvalidOperationException("Type is not Enum");
            }

            if (enumValues != null)
            {
                return(enumValues);
            }

            lock (this)
            {
                if (enumValues != null)
                {
                    return(enumValues);
                }

                string error = EnumValueList.TryParse(valueDefinition, out enumValues);
                if (error.HasText())
                {
                    throw new FormatException(error);
                }
            }

            return(enumValues);
        }
Пример #2
0
        protected override string PropertyValidation(PropertyInfo pi)
        {
            if (pi.Name == nameof(ValueDefinition) && ValueDefinition != null)
            {
                switch (Type)
                {
                case ChartParameterType.Enum: return(EnumValueList.TryParse(valueDefinition, out enumValues));

                case ChartParameterType.Number: return(NumberInterval.TryParse(valueDefinition, out numberInterval));

                case ChartParameterType.String: return(null);

                default: throw new InvalidOperationException();
                }
            }

            return(base.PropertyValidation(pi));
        }
        public static string?TryParse(string valueDefinition, out EnumValueList list)
        {
            list = new EnumValueList();
            foreach (var item in valueDefinition.SplitNoEmpty('|'))
            {
                string?error = EnumValue.TryParse(item, out EnumValue? val);
                if (error.HasText())
                {
                    return(error);
                }

                list.Add(val !);
            }

            if (list.Count == 0)
            {
                return("No parameter values set");
            }

            return(null);
        }