Beispiel #1
0
        /// <inheritdoc/>
        public override bool TryConvertToObjectItem(ConvertToObjectItemContext context, out object result, out string errorMessage)
        {
            result       = null;
            errorMessage = string.Empty;

            if (HasRequiredError(context.CsvItem))
            {
                errorMessage = CsvConfig.Current.ValidationMessage.GetRequiredError(context);
                return(false);
            }

            if (string.IsNullOrEmpty(context.CsvItem))
            {
                return(true);
            }

            if (float.TryParse(context.CsvItem, out float x))
            {
                result = x;
                return(true);
            }

            errorMessage = CsvConfig.Current.ValidationMessage.GetNumericConvertError(context);
            return(false);
        }
Beispiel #2
0
        /// <inheritdoc/>
        public override bool TryConvertToObjectItem(ConvertToObjectItemContext context, out object result, out string errorMessage)
        {
            result       = null;
            errorMessage = string.Empty;

            if (bool.TryParse(context.CsvItem, out bool x))
            {
                result = x;
                return(true);
            }

            if (string.IsNullOrEmpty(context.CsvItem) || context.CsvItem == "0")
            {
                result = false;
                return(true);
            }

            if (context.CsvItem == "1")
            {
                result = true;
                return(true);
            }

            errorMessage = CsvConfig.Current.ValidationMessage.GetBooleanConvertError(context);
            return(false);
        }
Beispiel #3
0
 /// <inheritdoc/>
 public override bool TryConvertToObjectItem(ConvertToObjectItemContext context, out object result, out string errorMessage)
 {
     result       = context.CsvItem;
     errorMessage = string.Empty;
     return(true);
 }
Beispiel #4
0
 public override bool TryConvertToObjectItem(ConvertToObjectItemContext context, out object?result, out string message)
 {
     result  = new ValueObject(context.CsvItem);
     message = string.Empty;
     return(true);
 }