示例#1
0
        public FieldFormat addSelectionValue(object value, string description)
        {
            if (string.IsNullOrEmpty(description))
            {
                throw new ArgumentException("Empty selection value description");
            }

            try
            {
                value = this.convertValue(value);
            }
            catch (ValidationException ex)
            {
                throw new ArgumentException(ex.Message, ex);
            }

            if (this.selectionValues == null)
            {
                this.selectionValues = new AgDictionary <NullableObject, string>();
            }

            this.selectionValues[new NullableObject(value)] = description;

            return(this);
        }
示例#2
0
        protected void createSelectionValues(string source, ClassicEncodingSettings settings)
        {
            if (source.Length == 0)
            {
                return;
            }

            var values = new AgDictionary <NullableObject, string>();

            var els = StringUtils.elements(source, settings.isUseVisibleSeparators());

            foreach (var el in els)
            {
                var valueSource = el.getValue();

                NullableObject selectionValue = new NullableObject(this.valueFromEncodedString(valueSource, settings, true));
                var            desc           = el.getName() ?? selectionValue.ToString();
                values[selectionValue] = desc;
            }

            this.setSelectionValues(values.Count > 0 ? values : null);
        }
示例#3
0
        //Sets field selection values.
        public FieldFormat setSelectionValues(AgDictionary <NullableObject, string> selectionValuesDictionary)
        {
            if (immutable)
            {
                throw new ArgumentException("Immutable");
            }

            if (selectionValues != null && selectionValues.Count == 0)
            {
                this.selectionValues = null;
                return(this);
            }

            this.selectionValues = (selectionValuesDictionary is ICloneable) ? selectionValuesDictionary : new AgDictionary <NullableObject, string>(selectionValuesDictionary);

            // If current default value doesn't match to new selection values, we change it to the first selection value from the list
            // ReSharper disable once PossibleNullReferenceException
            if (!this.selectionValues.ContainsKey(new NullableObject(this.getDefaultValue())) && !this.extendableSelectionValues)
            {
                this.setDefault(this.selectionValues.Keys.GetEnumerator().Current);
            }
            return(this);
        }