Skip to content

Commit

Permalink
Merge pull request #38 from JordiCorbilla/feature-1
Browse files Browse the repository at this point in the history
upgrade to .net 8
  • Loading branch information
JordiCorbilla authored Jun 10, 2024
2 parents a9ddf01 + 46554e8 commit b58cd11
Show file tree
Hide file tree
Showing 22 changed files with 211 additions and 210 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2023 Jordi Corbilla
Copyright (c) 2020-2024 Jordi Corbilla

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 3 additions & 6 deletions table.lib.tests/PivotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ public static List<TestClass> GetSampleOutput()
{
var list = new List<TestClass>
{
new TestClass
{
new() {
Field1 = 321121, Field2 = "AA", Field3 = 2121.32m, Field4 = true,
Field5 = new DateTime(1970, 1, 1), Field6 = 34.43
},
new TestClass
{
new() {
Field1 = 32321, Field2 = "BB", Field3 = 21111111.32m, Field4 = true,
Field5 = new DateTime(1970, 1, 1), Field6 = 34.43
},
new TestClass
{
new() {
Field1 = 321, Field2 = "CC", Field3 = 2121.32m, Field4 = true,
Field5 = new DateTime(1970, 1, 1), Field6 = 34.43
}
Expand Down
22 changes: 14 additions & 8 deletions table.lib.tests/table.lib.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
</ItemGroup>

<ItemGroup>
Expand Down
22 changes: 10 additions & 12 deletions table.lib/Base.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -30,20 +30,18 @@ public class Base<T>
public string ClassName { get; set; }
public List<PropertyName> PropertyNames { get; set; }
public Dictionary<string, int> MaxWidth { get; set; }
public Dictionary<string, string> ColumnNameOverrides { get; set; } = new Dictionary<string, string>();
public Dictionary<string, bool> ColumnFilter { get; set; } = new Dictionary<string, bool>();
public Dictionary<string, string> ColumnNameOverrides { get; set; } = [];
public Dictionary<string, bool> ColumnFilter { get; set; } = [];
public FilterAction ColumnAction { get; set; } = FilterAction.Exclude;
public ConsoleColor BackgroundColor { get; set; } = ConsoleColor.Black;
public ConsoleColor ForegroundColor { get; set; } = ConsoleColor.Green;
public List<T> Items { get; set; } = new List<T>();
public List<T> Items { get; set; } = [];

public Dictionary<string, List<HighlightOperator>> Operation { get; set; } =
new Dictionary<string, List<HighlightOperator>>();
public Dictionary<string, List<HighlightOperator>> Operation { get; set; } = [];

public Options Options { get; set; } = new Options();

public Dictionary<string, TextJustification> ColumnTextJustification { get; set; } =
new Dictionary<string, TextJustification>();
public Dictionary<string, TextJustification> ColumnTextJustification { get; set; } = [];

public string GetValue(T item, PropertyName property)
{
Expand All @@ -52,7 +50,7 @@ public string GetValue(T item, PropertyName property)
if (property.IsCollection)
{
var prop = item.GetType().GetProperties()[property.PropertyIndex];
value = prop.GetValue(item, new object[] { property.Index });
value = prop.GetValue(item, [property.Index]);
}
else
{
Expand All @@ -70,7 +68,7 @@ public object GetOriginalValue(T item, PropertyName property)
if (property.IsCollection)
{
var prop = item.GetType().GetProperties()[property.PropertyIndex];
value = prop.GetValue(item, new object[] { property.Index });
value = prop.GetValue(item, [property.Index]);
}
else
{
Expand Down Expand Up @@ -129,8 +127,8 @@ public void ConsoleRender(string value, string column)
Console.ForegroundColor = ForegroundColor;

if (Operation != null)
if (Operation.ContainsKey(column))
foreach (var item in Operation[column])
if (Operation.TryGetValue(column, out List<HighlightOperator> operation))
foreach (var item in operation)
switch (item.Type)
{
case HighlightType.Decimal:
Expand Down
2 changes: 1 addition & 1 deletion table.lib/CsvOptionType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 4 additions & 4 deletions table.lib/DbTable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -33,13 +33,13 @@ public class DbTable
public List<PropertyName> PropertyNames { get; set; }
public Dictionary<string, int> MaxWidth { get; set; }
public Options Options { get; set; } = new Options();
public Dictionary<string, bool> ColumnFilter { get; set; } = new Dictionary<string, bool>();
public Dictionary<string, bool> ColumnFilter { get; set; } = [];
public FilterAction ColumnAction { get; set; } = FilterAction.Exclude;

public DbTable(IEnumerable<IDictionary<string, object>> list, Options options = null)
{
PropertyNames = new List<PropertyName>();
MaxWidth = new Dictionary<string, int>();
PropertyNames = [];
MaxWidth = [];
Items = list;
if (options != null)
Options = options;
Expand Down
2 changes: 1 addition & 1 deletion table.lib/FilterAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion table.lib/HighlightOperation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions table.lib/HighlightOperator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,7 +22,7 @@

//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion table.lib/HighlightType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion table.lib/Options.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 10 additions & 10 deletions table.lib/Pivot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ public class Pivot<T>
public List<PropertyName> PropertyNames { get; set; }
public int MaxWidthProperties { get; set; }
public Dictionary<int, int> MaxWidthData { get; set; }
public Dictionary<string, string> ColumnNameOverrides { get; set; } = new Dictionary<string, string>();
public Dictionary<string, bool> ColumnFilter { get; set; } = new Dictionary<string, bool>();
public Dictionary<string, string> ColumnNameOverrides { get; set; } = [];
public Dictionary<string, bool> ColumnFilter { get; set; } = [];
public FilterAction ColumnAction { get; set; } = FilterAction.Exclude;
public ConsoleColor BackgroundColor { get; set; } = ConsoleColor.Black;
public ConsoleColor ForegroundColor { get; set; } = ConsoleColor.Green;
public List<T> Items { get; set; } = new List<T>();
public List<T> Items { get; set; } = [];

public Dictionary<string, List<HighlightOperator>> Operation { get; set; } =
new Dictionary<string, List<HighlightOperator>>();
[];

public Options Options { get; set; } = new Options();

public Dictionary<string, TextJustification> ColumnTextJustification { get; set; } =
new Dictionary<string, TextJustification>();
[];

/// <summary>
/// Where the magic happens.
Expand All @@ -35,11 +35,11 @@ public class Pivot<T>
/// <param name="options"></param>
public Pivot(List<T> list)
{
Data = new Dictionary<string, List<DynamicType>>();
Data = [];

PropertyNames = new List<PropertyName>();
PropertyNames = [];
MaxWidthProperties = "Field".Length;
MaxWidthData = new Dictionary<int, int>();
MaxWidthData = [];
Items = list;
var properties = typeof(T).GetProperties();
ClassName = typeof(T).Name;
Expand All @@ -48,7 +48,7 @@ public Pivot(List<T> list)
PropertyNames.Add(new PropertyName(property.Name));
if (property.Name.Length > MaxWidthProperties)
MaxWidthProperties = property.Name.Length;
Data.Add(property.Name, new List<DynamicType>());
Data.Add(property.Name, []);
}

var index = 0;
Expand Down Expand Up @@ -201,7 +201,7 @@ public string GetValue(T item, PropertyName property)
if (property.IsCollection)
{
var prop = item.GetType().GetProperties()[property.PropertyIndex];
value = prop.GetValue(item, new object[] { property.Index });
value = prop.GetValue(item, [property.Index]);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion table.lib/PropertyName.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion table.lib/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//MIT License

//Copyright (c) 2020-2023 Jordi Corbilla
//Copyright (c) 2020-2024 Jordi Corbilla

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit b58cd11

Please sign in to comment.