Skip to content

Commit

Permalink
Fix/collection size (#33)
Browse files Browse the repository at this point in the history
* Get only n+1 item

* update version
  • Loading branch information
ycherkes authored Jan 20, 2024
1 parent c498c5e commit 328cdf0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VarDump is a utility for serialization of runtime objects to C# or Visual Basic

Developed as a free alternative of [ObjectDumper.NET](https://github.com/thomasgalliker/ObjectDumper), which is not free for commercial use.

[![nuget version](https://img.shields.io/badge/Nuget-v0.2.13-blue)](https://www.nuget.org/packages/VarDump)
[![nuget version](https://img.shields.io/badge/Nuget-v0.2.14-blue)](https://www.nuget.org/packages/VarDump)
[![nuget downloads](https://img.shields.io/nuget/dt/VarDump?label=Downloads)](https://www.nuget.org/packages/VarDump)

## C# & VB Dumper:
Expand Down
8 changes: 4 additions & 4 deletions src/VarDump.Extensions/VarDump.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AssemblyName>VarDump.Extensions</AssemblyName>
<AssemblyVersion>0.2.13</AssemblyVersion>
<FileVersion>0.2.13</FileVersion>
<AssemblyVersion>0.2.14</AssemblyVersion>
<FileVersion>0.2.14</FileVersion>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Copyright>Copyright $([System.DateTime]::Now.Year) Yevhen Cherkes</Copyright>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>VarDump.Extensions</Title>
<Version>0.2.13</Version>
<Version>0.2.14</Version>
<Description>Extension methods that simplify the usage of the VarDump library.</Description>
<PackageProjectUrl>https://github.com/ycherkes/VarDump</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand All @@ -30,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="VarDump" Version="0.2.13" />
<PackageReference Include="VarDump" Version="0.2.14" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/VarDump/VarDump.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<AssemblyName>VarDump</AssemblyName>
<AssemblyVersion>0.2.13</AssemblyVersion>
<FileVersion>0.2.13</FileVersion>
<AssemblyVersion>0.2.14</AssemblyVersion>
<FileVersion>0.2.14</FileVersion>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Copyright>Copyright $([System.DateTime]::Now.Year) Yevhen Cherkes</Copyright>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>VarDump</Title>
<Version>0.2.13</Version>
<Version>0.2.14</Version>
<Description>VarDump is a utility for serialization runtime objects to C# and Visual Basic string.</Description>
<PackageProjectUrl>https://github.com/ycherkes/VarDump</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
6 changes: 3 additions & 3 deletions src/VarDump/Visitor/KnownTypes/CollectionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private CodeExpression VisitGroupingCollection(IEnumerable collection)

if (_maxCollectionSize < int.MaxValue)
{
items = items.Replace(_maxCollectionSize, CodeDomUtils.GetTooManyItemsExpression(_maxCollectionSize));
items = items.Take(_maxCollectionSize + 1).Replace(_maxCollectionSize, CodeDomUtils.GetTooManyItemsExpression(_maxCollectionSize));
}

CodeExpression expr = new CodeArrayCreateExpression(new CodeAnonymousTypeReference { ArrayRank = 1 }, items);
Expand Down Expand Up @@ -114,7 +114,7 @@ private CodeExpression VisitSimpleCollection(IEnumerable enumerable, Type elemen

if (_maxCollectionSize < int.MaxValue)
{
items = items.Replace(_maxCollectionSize, CodeDomUtils.GetTooManyItemsExpression(_maxCollectionSize));
items = items.Take(_maxCollectionSize + 1).Replace(_maxCollectionSize, CodeDomUtils.GetTooManyItemsExpression(_maxCollectionSize));
}

var type = enumerable.GetType();
Expand Down Expand Up @@ -185,7 +185,7 @@ private CodeExpression VisitAnonymousCollection(IEnumerable enumerable)

if (_maxCollectionSize < int.MaxValue)
{
items = items.Replace(_maxCollectionSize, CodeDomUtils.GetTooManyItemsExpression(_maxCollectionSize));
items = items.Take(_maxCollectionSize + 1).Replace(_maxCollectionSize, CodeDomUtils.GetTooManyItemsExpression(_maxCollectionSize));
}

var type = enumerable.GetType();
Expand Down
4 changes: 2 additions & 2 deletions src/VarDump/Visitor/KnownTypes/DictionaryVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private CodeExpression VisitSimpleDictionary(IDictionary dict)

if (_maxCollectionSize < int.MaxValue)
{
items = items.Replace(_maxCollectionSize, CodeDomUtils.GetTooManyItemsExpression(_maxCollectionSize));
items = items.Take(_maxCollectionSize + 1).Replace(_maxCollectionSize, CodeDomUtils.GetTooManyItemsExpression(_maxCollectionSize));
}

var type = dict.GetType();
Expand Down Expand Up @@ -103,7 +103,7 @@ private CodeExpression VisitAnonymousDictionary(IEnumerable dictionary)

if (_maxCollectionSize < int.MaxValue)
{
items = items.Replace(_maxCollectionSize, CodeDomUtils.GetTooManyItemsExpression(_maxCollectionSize));
items = items.Take(_maxCollectionSize + 1).Replace(_maxCollectionSize, CodeDomUtils.GetTooManyItemsExpression(_maxCollectionSize));
}

var type = dictionary.GetType();
Expand Down
7 changes: 5 additions & 2 deletions test/VarDump.UnitTests/TooManyItemsCollectionSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TooManyItemsCollectionSpec
[Fact]
public void DumpTooLongCollectionCSharp()
{
var collection = new List<int> { 1, 2, 3 }.AsReadOnly();
var collection = new List<int> { 1, 2, 3, 4 }.AsReadOnly();

var dumper = new CSharpDumper(new DumpOptions { MaxCollectionSize = 2 });

Expand All @@ -36,6 +36,7 @@ public void DumpTooLongDictionaryCSharp()
new Person{ Age = 32, FirstName = "Bob"},
new Person{ Age = 23, FirstName = "Alice"},
new Person{ Age = 13, FirstName = "Silvia"},
new Person{ Age = 44, FirstName = "Jon"}
}.ToDictionary(x => x.FirstName);

var dumper = new CSharpDumper(new DumpOptions { MaxCollectionSize = 2 });
Expand Down Expand Up @@ -75,6 +76,7 @@ public void DumpTooLongAnonymousDictionaryCSharp()
new { Age = 32, FirstName = "Bob"},
new { Age = 23, FirstName = "Alice"},
new { Age = 13, FirstName = "Silvia"},
new { Age = 44, FirstName = "Jon"}
}.ToDictionary(x => x.FirstName);

var dumper = new CSharpDumper(new DumpOptions { MaxCollectionSize = 2 });
Expand Down Expand Up @@ -116,6 +118,7 @@ public void DumpTooLongGroupingCollectionCSharp()
new Person{ Age = 32, FirstName = "Bob"},
new Person{ Age = 23, FirstName = "Alice"},
new Person{ Age = 13, FirstName = "Silvia"},
new Person{ Age = 44, FirstName = "Jon"}
}.GroupBy(x => x.FirstName).ToArray();

var dumper = new CSharpDumper(new DumpOptions { MaxCollectionSize = 2 });
Expand Down Expand Up @@ -153,7 +156,7 @@ public void DumpTooLongGroupingCollectionCSharp()
[Fact]
public void DumpTooLongCollectionVisualBasic()
{
var collection = new List<int> { 1, 2, 3 }.AsReadOnly();
var collection = new List<int> { 1, 2, 3, 4 }.AsReadOnly();

var dumper = new VisualBasicDumper(new DumpOptions { MaxCollectionSize = 2 });

Expand Down

0 comments on commit 328cdf0

Please sign in to comment.