Remove the dependency on System.ValueTuple (#63)

* Add an option to get tuple data via reflection.

* Removed non-relfection-based way of getting information about the tuples.

* Make methods static back.

* Remove the nuget dependency to System.ValueTuple
This commit is contained in:
Sergey Teplyakov
2018-02-23 03:24:41 -08:00
committed by Ben Adams
parent 7381924470
commit 125e373b45
7 changed files with 78 additions and 21 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Jobs;
@@ -14,5 +15,26 @@ namespace Ben.Demystifier.Benchmarks
[Benchmark(Description = "Demystify().ToString()")]
public string Demystify() => new Exception().Demystify().ToString();
[Benchmark(Description = "(left, right).ToString()")]
public string ToStringForTupleBased() => GetException(() => ReturnsTuple()).ToString();
[Benchmark(Description = "(left, right).Demystify().ToString()")]
public string ToDemystifyForTupleBased() => GetException(() => ReturnsTuple()).Demystify().ToString();
private static Exception GetException(Action action)
{
try
{
action();
throw new InvalidOperationException("Should not be reachable.");
}
catch (Exception e)
{
return e;
}
}
private static List<(int left, int right)> ReturnsTuple() => throw new Exception();
}
}

View File

@@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Xunit;
namespace Ben.Demystifier.Test

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
@@ -22,7 +20,7 @@ namespace Ben.Demystifier.Test
{
try
{
SimpleMethodThatThrows().Wait();
SimpleMethodThatThrows(null).Wait();
}
catch (Exception e)
{
@@ -39,9 +37,14 @@ namespace Ben.Demystifier.Test
Assert.Equal(original, afterDemystified);
}
async Task SimpleMethodThatThrows()
async Task SimpleMethodThatThrows(string value)
{
throw new InvalidOperationException("message");
if (value == null)
{
throw new InvalidOperationException("message");
}
await Task.Yield();
}
}
}