Helpers/Export: Code cleanup
Test / Run tests (push) Successful in 3m6s

This commit is contained in:
2026-10-01 12:29:47 +02:00
parent 66a1185dc3
commit ba7c37fd70
7 changed files with 18 additions and 40 deletions
+1 -1
View File
@@ -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<Row> {
public class Bki : CsvFile<Row> {
private readonly string _clientData;
@@ -7,7 +7,7 @@ using System.Text;
using System.Threading.Tasks;
namespace Elwig.Helpers.Export {
public abstract class Csv<T> : IExporter<T> {
public abstract class CsvFile<T> : IExporter<T> {
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<IEnumerable<object?>> {
public class CsvSimple : CsvFile<IEnumerable<object?>> {
public CsvSimple(string filename, char separator, Encoding encoding) :
base(filename, separator, encoding) {
+1 -1
View File
@@ -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<Transaction> {
public enum AddressMode { Omit = 0, Lines = 1, Full = 2 }
-15
View File
@@ -1,15 +0,0 @@
using Elwig.Models.Dtos;
using System;
namespace Elwig.Helpers.Export {
public class Elba : Csv<Transaction>, IBankingExporter {
public static new string FileExtension => "elba";
public Elba(string filename) : base(filename) { }
public override string FormatRow(Transaction row) {
throw new NotImplementedException();
}
}
}
-8
View File
@@ -1,8 +0,0 @@
using Elwig.Models.Dtos;
namespace Elwig.Helpers.Export {
/// <summary>
/// Interface for exporting banking data
/// </summary>
public interface IBankingExporter : IExporter<Transaction> { }
}
+12 -11
View File
@@ -33,24 +33,25 @@ namespace Elwig.Models.Dtos {
public DataTable(string name, string fullName, IEnumerable<T> 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<T> rows, IEnumerable<(string, string, string?)>? colNames = null) :