Added Prefix params Support + Test (#94)

Thank you!
This commit is contained in:
Martin Stühmer 2019-12-03 15:37:37 +01:00 committed by Ben Adams
parent 43c92b54e5
commit 1b99d61cf3
2 changed files with 49 additions and 4 deletions

View File

@ -51,7 +51,7 @@ namespace System.Diagnostics
{
var frame = stackFrames[i];
var method = frame.GetMethod();
// Always show last stackFrame
if (!ShowInStackTrace(method) && i < stackFrames.Length - 1)
{
@ -511,6 +511,11 @@ namespace System.Diagnostics
private static string GetPrefix(ParameterInfo parameter)
{
if (Attribute.IsDefined(parameter, typeof(ParamArrayAttribute), false))
{
return "params";
}
if (parameter.IsOut)
{
return "out";
@ -618,14 +623,14 @@ namespace System.Diagnostics
return false;
}
}
var type = method.DeclaringType;
if (type == null)
{
return true;
}
if (type == typeof(Task<>) && method.Name == "InnerInvoke")
{
return false;

View File

@ -0,0 +1,40 @@
namespace Ben.Demystifier.Test
{
using System;
using System.Diagnostics;
using Xunit;
public class ParameterParamTests
{
[Fact]
public void DemistifiesMethodWithParams()
{
Exception dex = null;
try
{
MethodWithParams(1, 2, 3);
}
catch (Exception e)
{
dex = e.Demystify();
}
// Assert
var stackTrace = dex.ToString();
stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace);
var trace = string.Join(string.Empty, stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
var expected = string.Join(string.Empty, new[] {
"System.ArgumentException: Value does not fall within the expected range.",
" at bool Ben.Demystifier.Test.ParameterParamTests.MethodWithParams(params int[] numbers)",
" at void Ben.Demystifier.Test.ParameterParamTests.DemistifiesMethodWithParams()"});
Assert.Equal(expected, trace);
}
private bool MethodWithParams(params int[] numbers)
{
throw new ArgumentException();
}
}
}