143 lines
4.0 KiB
C#
143 lines
4.0 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using DTLib.Demystifier.Enumerable;
|
|
|
|
namespace DTLib.Demystifier;
|
|
|
|
public class ResolvedMethod
|
|
{
|
|
public MethodBase? MethodBase { get; set; }
|
|
|
|
public Type? DeclaringType { get; set; }
|
|
|
|
public bool IsAsync { get; set; }
|
|
|
|
public bool IsLambda { get; set; }
|
|
|
|
public ResolvedParameter? ReturnParameter { get; set; }
|
|
|
|
public string? Name { get; set; }
|
|
|
|
public int? Ordinal { get; set; }
|
|
|
|
public string? GenericArguments { get; set; }
|
|
|
|
public Type[]? ResolvedGenericArguments { get; set; }
|
|
|
|
public MethodBase? SubMethodBase { get; set; }
|
|
|
|
public string? SubMethod { get; set; }
|
|
|
|
public EnumerableIList<ResolvedParameter> Parameters { get; set; }
|
|
|
|
public EnumerableIList<ResolvedParameter> SubMethodParameters { get; set; }
|
|
public int RecurseCount { get; internal set; }
|
|
|
|
internal bool IsSequentialEquivalent(ResolvedMethod obj)
|
|
{
|
|
return
|
|
IsAsync == obj.IsAsync &&
|
|
DeclaringType == obj.DeclaringType &&
|
|
Name == obj.Name &&
|
|
IsLambda == obj.IsLambda &&
|
|
Ordinal == obj.Ordinal &&
|
|
GenericArguments == obj.GenericArguments &&
|
|
SubMethod == obj.SubMethod;
|
|
}
|
|
|
|
public override string ToString() => AppendTo(new StringBuilder()).ToString();
|
|
|
|
public StringBuilder AppendTo(StringBuilder builder, bool fullName = true)
|
|
{
|
|
if (IsAsync) builder.Append("async ");
|
|
|
|
if (ReturnParameter is not null)
|
|
{
|
|
ReturnParameter.Append(builder);
|
|
builder.Append(' ');
|
|
}
|
|
|
|
if (DeclaringType is not null)
|
|
{
|
|
if (Name == ".ctor")
|
|
{
|
|
if (string.IsNullOrEmpty(SubMethod) && !IsLambda)
|
|
builder.Append("new ");
|
|
|
|
AppendDeclaringTypeName(builder, fullName);
|
|
}
|
|
else if (Name == ".cctor")
|
|
{
|
|
builder.Append("static ");
|
|
AppendDeclaringTypeName(builder, fullName);
|
|
}
|
|
else
|
|
{
|
|
AppendDeclaringTypeName(builder, fullName)
|
|
.Append('.')
|
|
.Append(Name);
|
|
}
|
|
}
|
|
else builder.Append(Name);
|
|
|
|
builder.Append(GenericArguments);
|
|
|
|
builder.Append('(');
|
|
if (MethodBase is not null)
|
|
{
|
|
var isFirst = true;
|
|
foreach (var param in Parameters)
|
|
{
|
|
if (isFirst)
|
|
isFirst = false;
|
|
else builder.Append(", ");
|
|
param.Append(builder);
|
|
}
|
|
}
|
|
else builder.Append('?');
|
|
|
|
builder.Append(')');
|
|
|
|
if (!string.IsNullOrEmpty(SubMethod) || IsLambda)
|
|
{
|
|
builder.Append('+');
|
|
builder.Append(SubMethod);
|
|
builder.Append('(');
|
|
if (SubMethodBase is not null)
|
|
{
|
|
var isFirst = true;
|
|
foreach (var param in SubMethodParameters)
|
|
{
|
|
if (isFirst)
|
|
isFirst = false;
|
|
else builder.Append(", ");
|
|
param.Append(builder);
|
|
}
|
|
}
|
|
else builder.Append('?');
|
|
|
|
builder.Append(')');
|
|
if (IsLambda)
|
|
{
|
|
builder.Append(" => { }");
|
|
|
|
if (Ordinal.HasValue)
|
|
{
|
|
builder.Append(" [");
|
|
builder.Append(Ordinal);
|
|
builder.Append(']');
|
|
}
|
|
}
|
|
}
|
|
|
|
if (RecurseCount > 0) builder.Append($" x {RecurseCount + 1:0}");
|
|
|
|
return builder;
|
|
}
|
|
|
|
private StringBuilder AppendDeclaringTypeName(StringBuilder builder, bool fullName = true)
|
|
{
|
|
return DeclaringType is not null ? builder.AppendTypeDisplayName(DeclaringType, fullName, true) : builder;
|
|
}
|
|
} |