-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create a VarDump.Extensions library #20
- Loading branch information
Showing
139 changed files
with
224 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using VarDump.Visitor; | ||
|
||
namespace VarDump.Extensions; | ||
|
||
public static class VarDumpExtensions | ||
{ | ||
public static Func<DumpOptions, IDumper> VarDumpFactory { get; set; } = VarDumpFactories.CSharp; | ||
|
||
public static string Dump(this object obj) | ||
{ | ||
return VarDumpFactory(DumpOptions.Default).Dump(obj); | ||
} | ||
|
||
public static string Dump(this object obj, DumpOptions options) | ||
{ | ||
return VarDumpFactory(options).Dump(obj); | ||
} | ||
|
||
public static void Dump(this object obj, DumpOptions options, TextWriter textWriter) | ||
{ | ||
VarDumpFactory(options).Dump(obj, textWriter); | ||
} | ||
} | ||
|
||
public class VarDumpFactories | ||
{ | ||
public static readonly Func<DumpOptions, IDumper> CSharp = options => new CSharpDumper(options); | ||
public static readonly Func<DumpOptions, IDumper> VisualBasic = options => new VisualBasicDumper(options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>latest</LangVersion> | ||
<AssemblyName>VarDump.Extensions</AssemblyName> | ||
<AssemblyVersion>0.2.9</AssemblyVersion> | ||
<FileVersion>0.2.9</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.9</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> | ||
<RepositoryUrl>https://github.com/ycherkes/VarDump.git</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageTags>dump;dumpobject;c#;visulabasic;debug</PackageTags> | ||
<NeutralLanguage>en</NeutralLanguage> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\README.md"> | ||
<Pack>True</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="VarDump" Version="0.2.9" /> | ||
</ItemGroup> | ||
|
||
</Project> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions
30
test/VarDump.Extensions.UnitTests/VarDump.Extensions.UnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net8.0;net461</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
<LangVersion>latest</LangVersion> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.6.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" /> | ||
<PackageReference Include="Portable.System.DateTimeOnly" Version="7.0.1" /> | ||
<PackageReference Include="xunit" Version="2.5.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\VarDump.Extensions\VarDump.Extensions.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
67 changes: 67 additions & 0 deletions
67
test/VarDump.Extensions.UnitTests/VarDumpExtensionsSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Xunit; | ||
|
||
namespace VarDump.Extensions.UnitTests; | ||
|
||
public class VarDumpExtensionsSpec | ||
{ | ||
[Fact] | ||
public void DumpAnonymousTypeCsharp() | ||
{ | ||
var anonymous = new[] | ||
{ | ||
new { Name = "Steeve", Age = (int?)int.MaxValue, Reference = "Test reference" }, | ||
new { Name = "Peter", Age = (int?)null, Reference = (string)null } | ||
}; | ||
|
||
VarDumpExtensions.VarDumpFactory = VarDumpFactories.CSharp; | ||
|
||
var result = anonymous.Dump(); | ||
|
||
Assert.Equal( | ||
@"var arrayOfAnonymousType = new [] | ||
{ | ||
new | ||
{ | ||
Name = ""Steeve"", | ||
Age = (int?)int.MaxValue, | ||
Reference = ""Test reference"" | ||
}, | ||
new | ||
{ | ||
Name = ""Peter"", | ||
Age = (int?)null, | ||
Reference = (string)null | ||
} | ||
}; | ||
", result); | ||
} | ||
|
||
[Fact] | ||
public void DumpAnonymousTypeVb() | ||
{ | ||
VarDumpExtensions.VarDumpFactory = VarDumpFactories.VisualBasic; | ||
|
||
var anonymous = new[] | ||
{ | ||
new { Name = "Steeve", Age = (int?)int.MaxValue, Reference = "Test reference" }, | ||
new { Name = "Peter", Age = (int?)null, Reference = (string)null } | ||
}; | ||
|
||
var result = anonymous.Dump(); | ||
|
||
Assert.Equal( | ||
@"Dim arrayOfAnonymousType = { | ||
New With { | ||
.Name = ""Steeve"", | ||
.Age = CType(Integer.MaxValue, Integer?), | ||
.Reference = ""Test reference"" | ||
}, | ||
New With { | ||
.Name = ""Peter"", | ||
.Age = CType(Nothing, Integer?), | ||
.Reference = CType(Nothing, String) | ||
} | ||
} | ||
", result); | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
test/UnitTests/AnonymousTypeSpec.cs → test/VarDump.UnitTests/AnonymousTypeSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/UnitTests/ArraySpec.cs → test/VarDump.UnitTests/ArraySpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
test/UnitTests/CustomCollectionSpec.cs → ...VarDump.UnitTests/CustomCollectionSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/UnitTests/DateTimeSpec.cs → test/VarDump.UnitTests/DateTimeSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
test/UnitTests/DiagnosticsSpec.cs → test/VarDump.UnitTests/DiagnosticsSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/UnitTests/DnsEndPointSpec.cs → test/VarDump.UnitTests/DnsEndPointSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/UnitTests/EnumerableRangeSpec.cs → .../VarDump.UnitTests/EnumerableRangeSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/UnitTests/ExceptionSpec.cs → test/VarDump.UnitTests/ExceptionSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
test/UnitTests/FlagsSpec.cs → test/VarDump.UnitTests/FlagsSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.