ReturnParameter fix for lambda_method (#11)

* ReturnParameter fix for lambda_method

* Bump version
This commit is contained in:
Ben Adams 2017-11-12 00:22:42 +01:00 committed by GitHub
parent 310a7b30cb
commit e7a2f46ff6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 4 deletions

View File

@ -9,7 +9,7 @@
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<IncludeSymbols>true</IncludeSymbols> <IncludeSymbols>true</IncludeSymbols>
<IncludeSource>true</IncludeSource> <IncludeSource>true</IncludeSource>
<Version>0.0.2</Version> <Version>0.0.3</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

View File

@ -59,8 +59,8 @@ namespace System.Diagnostics
var fileName = frame.GetFileName(); var fileName = frame.GetFileName();
var row = frame.GetFileLineNumber(); var row = frame.GetFileLineNumber();
var column = frame.GetFileColumnNumber(); var column = frame.GetFileColumnNumber();
var ilOffset = frame.GetILOffset();
if (string.IsNullOrEmpty(fileName)) if (string.IsNullOrEmpty(fileName) && ilOffset >= 0)
{ {
// .NET Framework and older versions of mono don't support portable PDBs // .NET Framework and older versions of mono don't support portable PDBs
// so we read it manually to get file name and line information // so we read it manually to get file name and line information
@ -167,9 +167,22 @@ namespace System.Diagnostics
} }
if (method is System.Reflection.MethodInfo mi) if (method is System.Reflection.MethodInfo mi)
{
var returnParameter = mi.ReturnParameter;
if (returnParameter != null)
{ {
methodDisplayInfo.ReturnParameter = GetParameter(mi.ReturnParameter); methodDisplayInfo.ReturnParameter = GetParameter(mi.ReturnParameter);
} }
else if (mi.ReturnType != null)
{
methodDisplayInfo.ReturnParameter = new ResolvedParameter
{
Prefix = "",
Name = "",
Type = TypeNameHelper.GetTypeDisplayName(mi.ReturnType, fullName: false, includeGenericParameterNames: true).ToString(),
};
}
}
if (method.IsGenericMethod) if (method.IsGenericMethod)
{ {

View File

@ -0,0 +1,54 @@
using System;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Xunit;
namespace Demystify
{
public class DynamicCompilation
{
[Fact]
public async Task DoesNotPreventStackTrace()
{
// Arrange
var expression = Expression.Throw(
Expression.New(
typeof(ArgumentException).GetConstructor(
new Type[] {typeof(string)}),
Expression.Constant( "Message")));
var lambda = Expression.Lambda<Action>(expression);
var action = lambda.Compile();
// Act
Exception demystifiedException = null;
try
{
await Task.Run(() => action()).ConfigureAwait(false);
}
catch(Exception ex)
{
demystifiedException = ex.Demystify();
}
// Assert
var stackTrace = demystifiedException.ToString();
stackTrace = ReplaceLineEndings.Replace(stackTrace, "");
var trace = stackTrace.Split(Environment.NewLine);
Assert.Equal(
new[] {
"System.ArgumentException: Message",
" at void lambda_method(Closure)",
" at Task Demystify.DynamicCompilation.DoesNotPreventThrowStackTrace()+()=>{}",
" at void System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, object state)",
" at async Task Demystify.DynamicCompilation.DoesNotPreventThrowStackTrace()"},
trace);
}
private Regex ReplaceLineEndings = new Regex(" in [^\n\r]+");
}
}