git_bsmd/ENI2/Util/Extensions.cs

31 lines
951 B
C#

// Copyright (c) 2025- schick Informatik
// Description: Some extensions only relevant to ENI itself
//
using bsmd.database;
using ExcelDataReader;
using System;
namespace ENI2.Util
{
internal static class Extensions
{
public static string ReadAsString(this IExcelDataReader reader, int index)
{
if (index >= reader.FieldCount) return null;
Type fieldType = reader.GetFieldType(index);
if (fieldType == null) return null;
if (fieldType == typeof(string))
return reader.GetString(index).Clean();
if (fieldType == typeof(DateTime))
return reader.GetDateTime(index).ToString();
if (fieldType == typeof(int))
return reader.GetInt32(index).ToString();
if (fieldType == typeof(double))
return ((int)reader.GetDouble(index)).ToString();
return null;
}
}
}