< Summary

Information
Class: MRA.Infrastructure.Excel.Attributes.ExcelColumnInfo
Assembly: MRA.Infrastructure
File(s): D:\a\MiguelRomerART\MiguelRomerART\MRA.Infrastructure\Excel\Attributes\ExcelColumnInfo.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 82
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 36
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Property()100%210%
get_Attribute()100%210%
ToString()100%210%
SameValues(...)0%342180%
GetValue(...)0%2040%
GetValueToPrint(...)0%210140%
GetStringFromDate(...)100%210%

File(s)

D:\a\MiguelRomerART\MiguelRomerART\MRA.Infrastructure\Excel\Attributes\ExcelColumnInfo.cs

#LineLine coverage
 1using System.Globalization;
 2using System.Reflection;
 3
 4namespace MRA.Infrastructure.Excel.Attributes;
 5
 6public class ExcelColumnInfo
 7{
 08    public PropertyInfo Property { get; set; }
 09    public ExcelColumnAttribute Attribute { get; set; }
 10
 11    public override string ToString()
 12    {
 013        return $"{Attribute.Name} => {Property.PropertyType}";
 14    }
 15
 16    public bool SameValues<T>(T object1, T object2)
 17    {
 018        var v1 = GetValue(object1);
 019        var v2 = GetValue(object2);
 20
 021        if(v1 is null && v2 is null)
 22        {
 023            return true;
 24        }
 025        else if (v1 is null || v2 is null)
 26        {
 027            return false;
 28        }
 029        else if (v1 is List<string> list1 && v2 is List<string> list2)
 30        {
 031            if (list1.Count != list2.Count) return false;
 32
 033            for (int i = 0; i < list1.Count; i++)
 34            {
 035                if (!list1[i].Equals(list2[i])) return false;
 36            }
 37
 038            return true;
 39        }
 40        else
 41        {
 042            return v1.Equals(v2);
 43        }
 44    }
 45
 46    public object? GetValue<T>(T? instance)
 47    {
 048        if (instance is null || Property == null) return null;
 49
 050        return Property.GetValue(instance);
 51    }
 52
 53    public string GetValueToPrint<T>(T instance)
 54    {
 055        var value = GetValue(instance);
 56
 057        if(value is string stringValue)
 58        {
 059            return stringValue;
 60        }
 061        else if (value is DateTime valueDate)
 62        {
 063            return GetStringFromDate(valueDate);
 64        }
 065        else if (value is bool boolValue)
 66        {
 067            return boolValue ? "True" : "False";
 68        }
 069        else if(value is List<string> listString)
 70        {
 071            return String.Join("\n", listString);
 72        }
 73
 074        return value?.ToString() ?? "null";
 75    }
 76
 77    public static string GetStringFromDate(DateTime date)
 78    {
 079        var cultureInfo = CultureInfo.GetCultureInfo("es-ES");
 080        return date.ToString("yyyy/MM/dd", cultureInfo);
 81    }
 82}