Ejemplo n.º 1
0
 /// <summary>
 /// Parses the given value as a char array.
 /// </summary>
 /// <param name="value">The value to parse.</param>
 /// <returns>The parsed char array.</returns>
 public override object Parse(string value)
 {
     if (NullHandler.IsNullRepresentation(value))
     {
         return(null);
     }
     value = TrimValue(value);
     return(value.ToCharArray());
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses the given value into a byte.
        /// </summary>
        /// <param name="value">The value to parse.</param>
        /// <returns>The parsed byte value.</returns>
        public override object Parse(string value)
        {
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }
            IFormatProvider provider = FormatProvider ?? CultureInfo.CurrentCulture;

            return(Byte.Parse(value, NumberStyles, provider));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses the given value as a byte array.
        /// </summary>
        /// <param name="value">The value to parse.</param>
        /// <returns>The parsed byte array.</returns>
        public override object Parse(string value)
        {
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }
            value = TrimValue(value);
            Encoding encoding = Encoding ?? Encoding.Default;

            return(encoding.GetBytes(value));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns the given value trimmed.
 /// </summary>
 /// <param name="value">The value to trim.</param>
 /// <returns>The value trimmed.</returns>
 public override object Parse(string value)
 {
     if (Trim && value != null)
     {
         value = TrimValue(value);
     }
     if (NullHandler.IsNullRepresentation(value))
     {
         return(null);
     }
     return(value);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Parses the given value into its equivalent enum value.
 /// </summary>
 /// <param name="value">The value to parse.</param>
 /// <returns>The enum value that was parsed.</returns>
 public override object Parse(string value)
 {
     if (Preprocessor != null)
     {
         value = Preprocessor(value);
     }
     if (NullHandler.IsNullRepresentation(value))
     {
         return(null);
     }
     return(parser(value));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Parses the given value as a char array.
 /// </summary>
 /// <param name="context">Holds information about the column current being processed.</param>
 /// <param name="value">The value to parse.</param>
 /// <returns>The parsed char array.</returns>
 public override object Parse(IColumnContext context, string value)
 {
     if (Preprocessor != null)
     {
         value = Preprocessor(value);
     }
     if (NullHandler.IsNullRepresentation(value))
     {
         return(null);
     }
     value = TrimValue(value);
     return(value.ToCharArray());
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Parses the given value into a byte.
        /// </summary>
        /// <param name="context">Holds information about the column current being processed.</param>
        /// <param name="value">The value to parse.</param>
        /// <returns>The parsed byte value.</returns>
        public override object Parse(IColumnContext context, string value)
        {
            if (Preprocessor != null)
            {
                value = Preprocessor(value);
            }
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }
            IFormatProvider provider = FormatProvider ?? CultureInfo.CurrentCulture;

            return(Byte.Parse(value, NumberStyles, provider));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Parses the given value as a byte array.
        /// </summary>
        /// <param name="value">The value to parse.</param>
        /// <returns>The parsed byte array.</returns>
        public override object Parse(string value)
        {
            if (Preprocessor != null)
            {
                value = Preprocessor(value);
            }
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }
            value = TrimValue(value);
            Encoding actualEncoding = Encoding ?? new UTF8Encoding(false);

            return(actualEncoding.GetBytes(value));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Parses the given value and returns a Guid instance.
 /// </summary>
 /// <param name="value">The value to parse.</param>
 /// <returns>The parsed Guid.</returns>
 public override object Parse(string value)
 {
     if (NullHandler.IsNullRepresentation(value))
     {
         return(null);
     }
     if (InputFormat == null)
     {
         return(Guid.Parse(value));
     }
     else
     {
         return(Guid.ParseExact(value, InputFormat));
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Parses the given value, returning a Double.
        /// </summary>
        /// <param name="value">The value to parse.</param>
        /// <returns>The parsed Double.</returns>
        public override object Parse(string value)
        {
            if (Preprocessor != null)
            {
                value = Preprocessor(value);
            }
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }
            IFormatProvider provider = FormatProvider ?? CultureInfo.CurrentCulture;

            value = TrimValue(value);
            return(Double.Parse(value, NumberStyles, provider));
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Parses the given value as a char.
 /// </summary>
 /// <param name="value">The value to parse.</param>
 /// <returns>The parsed char.</returns>
 public override object Parse(string value)
 {
     if (NullHandler.IsNullRepresentation(value))
     {
         return(null);
     }
     value = TrimValue(value);
     if (AllowTrailing || value.Length == 1)
     {
         return(value[0]);
     }
     else
     {
         throw new InvalidCastException();
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Parses the given value and returns a Guid instance.
        /// </summary>
        /// <param name="context">Holds information about the column current being processed.</param>
        /// <param name="value">The value to parse.</param>
        /// <returns>The parsed Guid.</returns>
        public override object Parse(IColumnContext context, string value)
        {
            if (Preprocessor != null)
            {
                value = Preprocessor(value);
            }
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }
            if (InputFormat == null)
            {
                return(Guid.Parse(value));
            }

            return(Guid.ParseExact(value, InputFormat));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Parses the given value into its equivilent boolean value.
 /// </summary>
 /// <param name="value">The value to parse.</param>
 /// <returns>True if the value equals the TrueString; otherwise, false.</returns>
 public override object Parse(string value)
 {
     if (NullHandler.IsNullRepresentation(value))
     {
         return(null);
     }
     value = TrimValue(value);
     if (String.Equals(value, TrueString, StringComparison.CurrentCultureIgnoreCase))
     {
         return(true);
     }
     if (String.Equals(value, FalseString, StringComparison.CurrentCultureIgnoreCase))
     {
         return(false);
     }
     throw new InvalidCastException();
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Parses the given value and returns a DateTime instance.
        /// </summary>
        /// <param name="value">The value to parse.</param>
        /// <returns>The parsed DateTime instance.</returns>
        public override object Parse(string value)
        {
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }
            IFormatProvider provider = FormatProvider ?? CultureInfo.CurrentCulture;

            if (InputFormat == null)
            {
                return(DateTime.Parse(value, provider));
            }
            else
            {
                return(DateTime.ParseExact(value, InputFormat, provider));
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Parses the given value as a char.
        /// </summary>
        /// <param name="context">Holds information about the column current being processed.</param>
        /// <param name="value">The value to parse.</param>
        /// <returns>The parsed char.</returns>
        public override object Parse(IColumnContext context, string value)
        {
            if (Preprocessor != null)
            {
                value = Preprocessor(value);
            }
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }
            value = TrimValue(value);
            if (AllowTrailing || value.Length == 1)
            {
                return(value[0]);
            }

            throw new InvalidCastException();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Parses the given value and returns a DateTime instance.
        /// </summary>
        /// <param name="context">Holds information about the column current being processed.</param>
        /// <param name="value">The value to parse.</param>
        /// <returns>The parsed DateTime instance.</returns>
        public override object Parse(IColumnContext context, string value)
        {
            if (Preprocessor != null)
            {
                value = Preprocessor(value);
            }
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }
            IFormatProvider provider = FormatProvider ?? CultureInfo.CurrentCulture;

            if (InputFormat == null)
            {
                return(DateTime.Parse(value, provider));
            }

            return(DateTime.ParseExact(value, InputFormat, provider));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Extracts a single record from the embedded data.
        /// </summary>
        /// <param name="value">The value containing the embedded data.</param>
        /// <returns>
        /// An object array containing the values read from the embedded data -or- null if there is no embedded data.
        /// </returns>
        public override object Parse(string value)
        {
            if (Preprocessor != null)
            {
                value = Preprocessor(value);
            }
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }

            StringReader         stringReader = new StringReader(value);
            SeparatedValueReader reader       = getReader(stringReader);

            if (reader.Read())
            {
                return(reader.GetValues());
            }
            return(null);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Extracts a single record from the embedded data.
        /// </summary>
        /// <param name="value">The value containing the embedded data.</param>
        /// <returns>
        /// An object array containing the values read from the embedded data -or- null if there is no embedded data.
        /// </returns>
        public override object Parse(string value)
        {
            if (Preprocessor != null)
            {
                value = Preprocessor(value);
            }
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }

            var stringReader = new StringReader(value);
            var reader       = new FixedLengthReader(stringReader, schema, Options);

            if (reader.Read())
            {
                return(reader.GetValues());
            }
            return(null);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Extracts a single record from the embedded data.
        /// </summary>
        /// <param name="context">Holds information about the column current being processed.</param>
        /// <param name="value">The value containing the embedded data.</param>
        /// <returns>
        /// An object array containing the values read from the embedded data -or- null if there is no embedded data.
        /// </returns>
        public override object Parse(IColumnContext context, string value)
        {
            if (Preprocessor != null)
            {
                value = Preprocessor(value);
            }
            if (NullHandler.IsNullRepresentation(value))
            {
                return(null);
            }

            var stringReader = new StringReader(value);
            var reader       = GetReader(stringReader);

            if (reader.Read())
            {
                return(reader.GetValues());
            }
            return(null);
        }