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); }
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); }
//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); }