diff --git a/Elwig/Helpers/Export/Bki.cs b/Elwig/Helpers/Export/Bki.cs index d4a0504..50d2d0a 100644 --- a/Elwig/Helpers/Export/Bki.cs +++ b/Elwig/Helpers/Export/Bki.cs @@ -8,7 +8,7 @@ namespace Elwig.Helpers.Export { using Row = Tuple<(string?, string?, string?, string?, string, int, string, bool, int), (string, int, string, string, string, int, string, double, double)>; - public class Bki : Csv { + public class Bki : CsvFile { private readonly string _clientData; diff --git a/Elwig/Helpers/Export/Csv.cs b/Elwig/Helpers/Export/CsvFile.cs similarity index 89% rename from Elwig/Helpers/Export/Csv.cs rename to Elwig/Helpers/Export/CsvFile.cs index ea59faa..029c390 100644 --- a/Elwig/Helpers/Export/Csv.cs +++ b/Elwig/Helpers/Export/CsvFile.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; namespace Elwig.Helpers.Export { - public abstract class Csv : IExporter { + public abstract class CsvFile : IExporter { public static string FileExtension => "csv"; @@ -15,11 +15,11 @@ namespace Elwig.Helpers.Export { protected readonly char Separator; protected string? Header; - public Csv(string filename, char separator = ';') : + public CsvFile(string filename, char separator = ';') : this(filename, separator, Utils.UTF8) { } - public Csv(string filename, char separator, Encoding encoding) { + public CsvFile(string filename, char separator, Encoding encoding) { _writer = new StreamWriter(filename, false, encoding); Separator = separator; } @@ -61,7 +61,7 @@ namespace Elwig.Helpers.Export { public abstract string FormatRow(T row); } - public class CsvSimple : Csv> { + public class CsvSimple : CsvFile> { public CsvSimple(string filename, char separator, Encoding encoding) : base(filename, separator, encoding) { diff --git a/Elwig/Helpers/Export/Ebics.cs b/Elwig/Helpers/Export/Ebics.cs index 9e77bb3..4d80549 100644 --- a/Elwig/Helpers/Export/Ebics.cs +++ b/Elwig/Helpers/Export/Ebics.cs @@ -9,7 +9,7 @@ using System.Security; using System.Threading.Tasks; namespace Elwig.Helpers.Export { - public class Ebics(PaymentVar variant, string filename, int version, Ebics.AddressMode mode = Ebics.AddressMode.Full) : IBankingExporter { + public class Ebics(PaymentVar variant, string filename, int version, Ebics.AddressMode mode = Ebics.AddressMode.Full) : IExporter { public enum AddressMode { Omit = 0, Lines = 1, Full = 2 } diff --git a/Elwig/Helpers/Export/Elba.cs b/Elwig/Helpers/Export/Elba.cs deleted file mode 100644 index 8f9d9f1..0000000 --- a/Elwig/Helpers/Export/Elba.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Elwig.Models.Dtos; -using System; - -namespace Elwig.Helpers.Export { - public class Elba : Csv, IBankingExporter { - - public static new string FileExtension => "elba"; - - public Elba(string filename) : base(filename) { } - - public override string FormatRow(Transaction row) { - throw new NotImplementedException(); - } - } -} diff --git a/Elwig/Helpers/Export/IBankingExporter.cs b/Elwig/Helpers/Export/IBankingExporter.cs deleted file mode 100644 index 2df4b2e..0000000 --- a/Elwig/Helpers/Export/IBankingExporter.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Elwig.Models.Dtos; - -namespace Elwig.Helpers.Export { - /// - /// Interface for exporting banking data - /// - public interface IBankingExporter : IExporter { } -} diff --git a/Elwig/Helpers/Export/Ods.cs b/Elwig/Helpers/Export/OdsFile.cs similarity index 100% rename from Elwig/Helpers/Export/Ods.cs rename to Elwig/Helpers/Export/OdsFile.cs diff --git a/Elwig/Models/Dtos/DataTable.cs b/Elwig/Models/Dtos/DataTable.cs index 2090b84..ac46298 100644 --- a/Elwig/Models/Dtos/DataTable.cs +++ b/Elwig/Models/Dtos/DataTable.cs @@ -33,24 +33,25 @@ namespace Elwig.Models.Dtos { public DataTable(string name, string fullName, IEnumerable rows, IEnumerable<(string, string, string?, int?)>? colNames = null) { _fields = typeof(T).GetFields(); _properties = typeof(T).GetProperties(); - colNames ??= _properties.Select(p => p.Name).Union(_fields.Select(f => f.Name)).Select(i => (i, i, (string?)null, (int?)null)).ToList(); - _map = colNames.Select(n => (n.Item2, _properties.FirstOrDefault(p => p?.Name == n.Item1, null), _fields.FirstOrDefault(f => f?.Name == n.Item1, null))).ToArray(); + colNames ??= [.. _properties.Select(p => p.Name).Union(_fields.Select(f => f.Name)).Select(i => (i, i, (string?)null, (int?)null))]; + _map = [.. colNames.Select(n => (n.Item2, _properties.FirstOrDefault(p => p?.Name == n.Item1, null), _fields.FirstOrDefault(f => f?.Name == n.Item1, null)))]; Name = name; FullName = fullName; Rows = rows; - ColumnFlatTypes = ColumnTypes.SelectMany(type => { + ColumnFlatTypes = [.. ColumnTypes.SelectMany(type => { var elType = type?.GetElementType(); - return type != null && type.IsValueType && type.Name.StartsWith("ValueTuple") ? type.GetFields().Select(f => f.FieldType) : - type != null && elType != null && type.IsArray && elType.IsValueType && elType.Name.StartsWith("ValueTuple") ? elType.GetFields().Select(f => f.FieldType) : + return type != null && type.IsValueType && type.Name.StartsWith("ValueTuple") ? type.GetFields().Select(f => (Type?)f.FieldType) : + type != null && elType != null && type.IsArray && elType.IsValueType && elType.Name.StartsWith("ValueTuple") ? elType.GetFields().Select(f => (Type?)f.FieldType) : [type]; - }).ToList(); - ColumnSpans = ColumnTypes.Select(type => { + })]; + ColumnSpans = [.. ColumnTypes.Select(type => { var elType = type?.GetElementType(); return type != null && type.IsValueType && type.Name.StartsWith("ValueTuple") ? type.GetFields().Length : - type != null && elType != null && type.IsArray && elType.IsValueType && elType.Name.StartsWith("ValueTuple") ? elType.GetFields().Length : 1; - }).ToList(); - ColumnWidths = colNames.Select(c => c.Item4).ToList(); - ColumnUnits = colNames.Select(c => c.Item3?.Split("|").Select(p => p.Length == 0 ? null : p).ToArray() ?? []).ToList(); + type != null && elType != null && type.IsArray && elType.IsValueType && elType.Name.StartsWith("ValueTuple") ? elType.GetFields().Length : + 1; + })]; + ColumnWidths = [.. colNames.Select(c => c.Item4)]; + ColumnUnits = [.. colNames.Select(c => c.Item3?.Split("|").Select(p => p.Length == 0 ? null : p).ToArray() ?? [])]; } public DataTable(string name, string fullName, IEnumerable rows, IEnumerable<(string, string, string?)>? colNames = null) :