提交 01282fb6 编写于 作者: A Andrew Casey

Don't call GetGenericsArguments unless IsGeneric is true

Fixes #8452
上级 4425532d
......@@ -4,6 +4,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.CodeAnalysis.Scripting;
......@@ -777,6 +778,15 @@ public void DebuggerProxy_ArrayBuilder()
);
}
[WorkItem(8542, "https://github.com/dotnet/roslyn/issues/8452")]
[Fact]
public void FormatConstructorSignature()
{
var constructor = typeof(object).GetTypeInfo().DeclaredConstructors.Single();
var signature = ((CommonObjectFormatter)s_formatter).FormatMethodSignature(constructor);
Assert.Equal("object..ctor()", signature); // Checking for exceptions, more than particular output.
}
// The stack trace contains line numbers. We use a #line directive
// so that the baseline doesn't need to be updated every time this
// file changes.
......
......@@ -101,7 +101,7 @@ public override string FormatUnhandledException(Exception e)
/// Returns a method signature display string. Used to display stack frames.
/// </summary>
/// <returns>Null if the method is a compiler generated method that shouldn't be displayed to the user.</returns>
protected virtual string FormatMethodSignature(MethodBase method)
protected internal virtual string FormatMethodSignature(MethodBase method)
{
var pooled = PooledStringBuilder.GetInstance();
var builder = pooled.Builder;
......@@ -112,7 +112,10 @@ protected virtual string FormatMethodSignature(MethodBase method)
builder.Append(TypeNameFormatter.FormatTypeName(declaringType, options));
builder.Append('.');
builder.Append(method.Name);
if (method.IsGenericMethod)
{
builder.Append(TypeNameFormatter.FormatTypeArguments(method.GetGenericArguments(), options));
}
builder.Append('(');
......
......@@ -93,7 +93,7 @@ public virtual string FormatTypeArguments(Type[] typeArguments, CommonTypeNameFo
if (typeArguments.Length == 0)
{
return "";
throw new ArgumentException(null, nameof(typeArguments));
}
var pooled = PooledStringBuilder.GetInstance();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册