Exemple #1
0
 /// <summary>
 /// Copy constructor for the FieldValue object.
 /// </summary>
 /// <param name="source"></param>
 public FieldValue(FieldValue source)
 {
     CopyAllSettings(source);
 }
Exemple #2
0
 /// <summary>
 /// Updates properties of current object with properties of source object.
 /// </summary>
 /// <param name="source"></param>
 public void ApplyChanges(FieldValue source)
 {
     CopyAllSettings(source);
 }
Exemple #3
0
        /// <summary>
        /// Performs value validation.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private object ValidateValue(object value)
        {
            Exception ex = null;

            ValidationException = null;
            object temp = _value;

            // Performs type and length validation.
            if (OutField != null)
            {
                if (OutField.Domain != null)
                {
                    if (value is string)
                    {
                        foreach (var item in OutField.Domain)
                        {
                            if (item.Value == value as string)
                            {
                                temp = item;
                                break;
                            }
                        }
                    }
                    else
                    {
                        temp = value;
                    }
                }
                else
                {
                    temp = FieldValue.ValidateValue(OutField, value, out ex);
                    if (ex != null && (value == null || string.IsNullOrWhiteSpace(value.ToString())))
                    {
                        // Special handling of validation errors due to null or empty input - set value to null and
                        // only set ValidationException if empty values are not allowed
                        temp = null;
                        if (!AllowEmptyValues)
                        {
                            ValidationException = new Exception(Strings.EmptyEntryError);
                        }
                    }
                    else if (ex != null)
                    {
                        ValidationException = new Exception(Strings.InvalidValue);
                    }
                }
            }

            if (ex == null)
            {
                if (Choices != null)
                {
                    // Checks for duplicate entries.
                    if (Choices.Any(c => c != this && FieldValueEqualityComparer.EqualObject(c.ValueInCorrectType, temp)))
                    {
                        ValidationException = new ArgumentException(Strings.DuplicateError);
                    }
                }
            }

            return(temp);
        }