Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/indice.Edi/EdiReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using indice.Edi.FormatSpec;

namespace indice.Edi
{
Expand Down Expand Up @@ -332,9 +333,9 @@ private EdiContainerType Peek() {
/// <summary>
/// Reads the next EDI token from the stream as a <see cref="Nullable{Decimal}"/>.
/// </summary>
/// <param name="picture">The <see cref="Nullable{Picture}"/> is the format information needed to parse this into a float</param>
/// <param name="formatSpec">The <see cref="Nullable{IFormatSpec}"/> is the format information needed to parse this into a float</param>
/// <returns>A <see cref="Nullable{Decimal}"/>. This method will return <c>null</c> at the end of an array.</returns>
public abstract decimal? ReadAsDecimal(Picture? picture);
public abstract decimal? ReadAsDecimal(IFormatSpec formatSpec);

/// <summary>
/// Reads the next EDI token from the stream as a <see cref="Nullable{DateTime}"/>.
Expand All @@ -348,7 +349,7 @@ internal virtual bool ReadInternal() {
throw new NotImplementedException();
}

internal decimal? ReadAsDecimalInternal(Picture? picture) {
internal decimal? ReadAsDecimalInternal(IFormatSpec formatSpec) {
EdiToken t;
if (!ReadInternal()) {
SetToken(EdiToken.None);
Expand All @@ -368,7 +369,7 @@ internal virtual bool ReadInternal() {
return null;
}
decimal d;
if (s.TryParse(picture, Grammar.DecimalMark, out d)) {
if (s.TryParse(formatSpec, Grammar.DecimalMark, out d)) {
SetToken(EdiToken.Float, d, false);
return d;
}
Expand Down
8 changes: 4 additions & 4 deletions src/indice.Edi/EdiSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ internal static void PopulateDateTimeValue(EdiReader reader, EdiStructure struct
var dateString = cache.ContainsPath(valueInfo.Path) ? cache.ReadAsString(valueInfo.Path) :
read ? reader.ReadAsString() : (string)reader.Value;
if (dateString != null) {
dateString = dateString.Substring(0, valueInfo.Picture.Scale);
dateString = dateString.Substring(0, valueInfo.FormatSpec.Scale);
var date = default(DateTime);
if (dateString.TryParseEdiDate(valueInfo.Format, CultureInfo.InvariantCulture, out date)) {
var existingDateObject = descriptor.Info.GetValue(structure.Instance);
Expand All @@ -258,8 +258,8 @@ internal static void PopulateDateTimeValue(EdiReader reader, EdiStructure struct
internal static void PopulateDecimalValue(EdiReader reader, EdiStructure structure, EdiPropertyDescriptor descriptor, bool read) {
var cache = structure.CachedReads;
var valueInfo = descriptor.ValueInfo;
var numberFloat = cache.ContainsPath(valueInfo.Path) ? cache.ReadAsDecimal(valueInfo.Path, descriptor.ValueInfo.Picture, reader.Grammar.DecimalMark) :
read ? reader.ReadAsDecimal(descriptor.ValueInfo.Picture) : (decimal?)reader.Value;
var numberFloat = cache.ContainsPath(valueInfo.Path) ? cache.ReadAsDecimal(valueInfo.Path, descriptor.ValueInfo.FormatSpec, reader.Grammar.DecimalMark) :
read ? reader.ReadAsDecimal(descriptor.ValueInfo.FormatSpec) : (decimal?)reader.Value;
if (numberFloat != null) {
descriptor.Info.SetValue(structure.Instance, numberFloat);
}
Expand Down Expand Up @@ -618,7 +618,7 @@ private static void SerializeStructure(EdiWriter writer, Stack<EdiStructure> sta
else if (path.ComponentIndex != property.PathInfo.ComponentIndex)
writer.WriteToken(EdiToken.ComponentStart);
}
writer.WriteValue(value, property.ValueInfo.Picture, property.ValueInfo.Format);
writer.WriteValue(value, property.ValueInfo.FormatSpec, property.ValueInfo.Format);
} else {
// this is somekind of structure. Group/Message/Segment/SegmentGroup/Element
// is it a collection of some kind?
Expand Down
5 changes: 3 additions & 2 deletions src/indice.Edi/EdiTextReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using indice.Edi.FormatSpec;

namespace indice.Edi
{
Expand Down Expand Up @@ -51,8 +52,8 @@ public override bool Read() {
/// Reads the next EDI token from the stream as a <see cref="Nullable{Decimal}"/>.
/// </summary>
/// <returns>A <see cref="Nullable{Decimal}"/>. This method will return <c>null</c> at the end of an array.</returns>
public override decimal? ReadAsDecimal(Picture? picture = null) {
return ReadAsDecimalInternal(picture);
public override decimal? ReadAsDecimal(IFormatSpec formatSpec = null) {
return ReadAsDecimalInternal(formatSpec);
}

/// <summary>
Expand Down
57 changes: 29 additions & 28 deletions src/indice.Edi/EdiTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.IO;
using System.Xml;
using indice.Edi.FormatSpec;
using indice.Edi.Utilities;

namespace indice.Edi
Expand Down Expand Up @@ -149,7 +150,7 @@ public override void WriteRaw(string fragment) {
/// Writes a <see cref="String"/> value.
/// </summary>
/// <param name="value">The <see cref="String"/> value to write.</param>
public override void WriteValue(string value, Picture? picture) {
public override void WriteValue(string value, IFormatSpec formatSpec) {
InternalWriteValue(EdiToken.String);
WriteEscapedString(value);
}
Expand Down Expand Up @@ -224,83 +225,83 @@ private void WriteEscapedString(string value) {
/// Writes a <see cref="Int32"/> value.
/// </summary>
/// <param name="value">The <see cref="Int32"/> value to write.</param>
public override void WriteValue(int value, Picture? picture = null) {
public override void WriteValue(int value, IFormatSpec formatSpec = null) {
InternalWriteValue(EdiToken.Integer);
_writer.Write(((int?)value).ToEdiString(picture));
_writer.Write(((int?)value).ToEdiString(formatSpec));
//WriteIntegerValue(value, picture);
}

/// <summary>
/// Writes a <see cref="UInt32"/> value.
/// </summary>
/// <param name="value">The <see cref="UInt32"/> value to write.</param>
public override void WriteValue(uint value, Picture? picture = null) {
public override void WriteValue(uint value, IFormatSpec formatSpec = null) {
InternalWriteValue(EdiToken.Integer);
_writer.Write(((int?)value).ToEdiString(picture));
_writer.Write(((int?)value).ToEdiString(formatSpec));
//WriteIntegerValue(value, picture);
}

/// <summary>
/// Writes a <see cref="Int64"/> value.
/// </summary>
/// <param name="value">The <see cref="Int64"/> value to write.</param>
public override void WriteValue(long value, Picture? picture = null) {
public override void WriteValue(long value, IFormatSpec formatSpec = null) {
InternalWriteValue(EdiToken.Float);
_writer.Write(value.ToEdiString(picture));
_writer.Write(value.ToEdiString(formatSpec));
//WriteIntegerValue(value, picture);
}

/// <summary>
/// Writes a <see cref="UInt64"/> value.
/// </summary>
/// <param name="value">The <see cref="UInt64"/> value to write.</param>
public override void WriteValue(ulong value, Picture? picture = null) {
public override void WriteValue(ulong value, IFormatSpec formatSpec = null) {
InternalWriteValue(EdiToken.Integer);
_writer.Write(((int?)value).ToEdiString(picture));
_writer.Write(((int?)value).ToEdiString(formatSpec));
//WriteIntegerValue(value, picture);
}

/// <summary>
/// Writes a <see cref="Single"/> value.
/// </summary>
/// <param name="value">The <see cref="Single"/> value to write.</param>
public override void WriteValue(float value, Picture? picture) {
public override void WriteValue(float value, IFormatSpec formatSpec) {
InternalWriteValue(EdiToken.Float);
_writer.Write(value.ToEdiString(picture, Grammar.DecimalMark));
_writer.Write(value.ToEdiString(formatSpec, Grammar.DecimalMark));
}

/// <summary>
/// Writes a <see cref="Nullable{Single}"/> value.
/// </summary>
/// <param name="value">The <see cref="Nullable{Single}"/> value to write.</param>
public override void WriteValue(float? value, Picture? picture = null) {
public override void WriteValue(float? value, IFormatSpec formatSpec = null) {
if (value == null) {
WriteNull();
} else {
InternalWriteValue(EdiToken.Float);
_writer.Write(value.ToEdiString(picture, Grammar.DecimalMark));
_writer.Write(value.ToEdiString(formatSpec, Grammar.DecimalMark));
}
}

/// <summary>
/// Writes a <see cref="Double"/> value.
/// </summary>
/// <param name="value">The <see cref="Double"/> value to write.</param>
public override void WriteValue(double value, Picture? picture = null) {
public override void WriteValue(double value, IFormatSpec formatSpec = null) {
InternalWriteValue(EdiToken.Float);
_writer.Write(value.ToEdiString(picture, Grammar.DecimalMark));
_writer.Write(value.ToEdiString(formatSpec, Grammar.DecimalMark));
}

/// <summary>
/// Writes a <see cref="Nullable{Double}"/> value.
/// </summary>
/// <param name="value">The <see cref="Nullable{Double}"/> value to write.</param>
public override void WriteValue(double? value, Picture? picture = null) {
public override void WriteValue(double? value, IFormatSpec formatSpec = null) {
if (value == null) {
WriteNull();
} else {
InternalWriteValue(EdiToken.Float);
_writer.Write(value.ToEdiString(picture, Grammar.DecimalMark));
_writer.Write(value.ToEdiString(formatSpec, Grammar.DecimalMark));
}
}

Expand All @@ -317,19 +318,19 @@ public override void WriteValue(bool value) {
/// Writes a <see cref="Int16"/> value.
/// </summary>
/// <param name="value">The <see cref="Int16"/> value to write.</param>
public override void WriteValue(short value, Picture? picture) {
public override void WriteValue(short value, IFormatSpec formatSpec) {
InternalWriteValue(EdiToken.Integer);
_writer.Write(((int?)value).ToEdiString(picture));
_writer.Write(((int?)value).ToEdiString(formatSpec));
//WriteIntegerValue(value, picture);
}

/// <summary>
/// Writes a <see cref="UInt16"/> value.
/// </summary>
/// <param name="value">The <see cref="UInt16"/> value to write.</param>
public override void WriteValue(ushort value, Picture? picture) {
public override void WriteValue(ushort value, IFormatSpec formatSpec) {
InternalWriteValue(EdiToken.Integer);
_writer.Write(((int?)value).ToEdiString(picture));
_writer.Write(((int?)value).ToEdiString(formatSpec));
//WriteIntegerValue(value, picture);
}

Expand All @@ -347,19 +348,19 @@ public override void WriteValue(char value) {
/// Writes a <see cref="SByte"/> value.
/// </summary>
/// <param name="value">The <see cref="SByte"/> value to write.</param>
public override void WriteValue(sbyte value, Picture? picture) {
public override void WriteValue(sbyte value, IFormatSpec formatSpec) {
InternalWriteValue(EdiToken.Integer);
_writer.Write(((int?)value).ToEdiString(picture));
_writer.Write(((int?)value).ToEdiString(formatSpec));
//WriteIntegerValue(value, picture);
}

/// <summary>
/// Writes a <see cref="Decimal"/> value.
/// </summary>
/// <param name="value">The <see cref="Decimal"/> value to write.</param>
public override void WriteValue(decimal value, Picture? picture) {
public override void WriteValue(decimal value, IFormatSpec formatSpec) {
InternalWriteValue(EdiToken.Float);
_writer.Write(value.ToEdiString(picture, Grammar.DecimalMark));
_writer.Write(value.ToEdiString(formatSpec, Grammar.DecimalMark));
}

/// <summary>
Expand Down Expand Up @@ -428,7 +429,7 @@ private void EnsureWriteBuffer() {
}
}

private void WriteIntegerValue(long value, Picture? picture) {
private void WriteIntegerValue(long value, IFormatSpec formatSpec) {
if (value >= 0 && value <= 9) {
_writer.Write((char)('0' + value));
} else {
Expand All @@ -438,11 +439,11 @@ private void WriteIntegerValue(long value, Picture? picture) {
_writer.Write('-');
}

WriteIntegerValue(uvalue, picture);
WriteIntegerValue(uvalue, formatSpec);
}
}

private void WriteIntegerValue(ulong uvalue, Picture? picture) {
private void WriteIntegerValue(ulong uvalue, IFormatSpec formatSpec) {
if (uvalue <= 9) {
_writer.Write((char)('0' + uvalue));
} else {
Expand Down
Loading