Skip to content

Commit

Permalink
Fix the non-public collection serialization. (#34)
Browse files Browse the repository at this point in the history
* Fix the non-public collection serialization. Enumerable.Range(0, 10) was wrongly dumped in NET80 as new RangeIterator { ... }

* update reference to vardump nuget package
  • Loading branch information
ycherkes authored Jan 24, 2024
1 parent 241cf8a commit 29f382f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 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.14-blue)](https://www.nuget.org/packages/VarDump)
[![nuget version](https://img.shields.io/badge/Nuget-v0.2.15-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.14</AssemblyVersion>
<FileVersion>0.2.14</FileVersion>
<AssemblyVersion>0.2.15</AssemblyVersion>
<FileVersion>0.2.15</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.14</Version>
<Version>0.2.15</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.14" />
<PackageReference Include="VarDump" Version="0.2.15" />
</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.14</AssemblyVersion>
<FileVersion>0.2.14</FileVersion>
<AssemblyVersion>0.2.15</AssemblyVersion>
<FileVersion>0.2.15</FileVersion>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Copyright>Copyright $([System.DateTime]::Now.Year) Yevhen Cherkes</Copyright>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>VarDump</Title>
<Version>0.2.14</Version>
<Version>0.2.15</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
3 changes: 2 additions & 1 deletion src/VarDump/Visitor/KnownTypes/CollectionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ private CodeExpression VisitSimpleCollection(IEnumerable enumerable, Type elemen
var type = enumerable.GetType();

var isImmutableOrFrozen = type.IsPublicImmutableOrFrozenCollection();
var isCollection = IsCollection(enumerable);

if (type.IsArray || isImmutableOrFrozen || !IsCollection(enumerable))
if (type.IsArray || isImmutableOrFrozen || !type.IsPublic || !isCollection)
{
if (type.IsArray && ((Array)enumerable).Rank > 1)
{
Expand Down
21 changes: 21 additions & 0 deletions test/VarDump.UnitTests/CollectionSpec.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace VarDump.UnitTests;
Expand All @@ -23,6 +24,26 @@ public void DumpReadOnlyCollectionCSharp()
""", result);
}

[Fact]
public void DumpEnumerableRangeCSharp()
{
var range = Enumerable.Range(0, 3);

var dumper = new CSharpDumper();

var result = dumper.Dump(range);

Assert.Equal("""
var rangeIteratorOfInt = new int[]
{
0,
1,
2
};
""", result);
}

[Fact]
public void DumpReadOnlyCollectionVisualBasic()
{
Expand Down

0 comments on commit 29f382f

Please sign in to comment.