Beispiel #1
0
        /// <summary>
        /// Returns FieldValue into string format with
        /// its type and usage considered.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            if (Value != null)
            {
                if (OutField != null)
                {
                    var objValue = Value;

                    if (OutField.Domain != null)
                    {
                        var result = OutField.Domain.FirstOrDefault(c => FieldValueEqualityComparer.EqualObject(c.Value, Value));
                        objValue = result.Key;
                    }
                    string strValue = Convert.ToString(objValue, CultureInfo.InvariantCulture);
                    return(OutField.Type == Field.FieldType.String ||
                           OutField.Type == Field.FieldType.GUID ||
                           OutField.Type == Field.FieldType.XML ?
                           string.Format("'{0}'", strValue) : string.Format("{0}", strValue));
                }
                return(Convert.ToString(Value, CultureInfo.InvariantCulture));
            }
            return("NULL");
        }
Beispiel #2
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);
        }