-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClassGenericTypeSystemCanonicalBeautifier.cs
More file actions
63 lines (54 loc) · 1.62 KB
/
Copy pathClassGenericTypeSystemCanonicalBeautifier.cs
File metadata and controls
63 lines (54 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Microsoft.Extensions.Logging;
using NetStackBeautifier.Core;
namespace NetStackBeautifier.Services.LineBeautifiers;
internal class ClassGenericTypeSystemCanonicalBeautifier<T> : LineBeautifierBase<T>
where T : BeautifierBase<T>
{
public ClassGenericTypeSystemCanonicalBeautifier(
ILogger<ClassGenericTypeSystemCanonicalBeautifier<T>> logger) : base(logger)
{
}
protected override Task<FrameItem> BeautifyImpAsync(FrameItem line, CancellationToken cancellationToken = default)
{
if (line.FullClass is null)
{
return Task.FromResult(line);
}
if (!line.FullClass.GenericParameterTypes.NullAsEmpty().Any())
{
return Task.FromResult(line);
}
int tCount = 0;
List<string> result = new List<string>();
List<string> rawResult = new List<string>();
foreach (string item in line.FullClass.GenericParameterTypes)
{
rawResult.Add(item);
if (string.Equals(item, "System.__Canon", StringComparison.OrdinalIgnoreCase))
{
result.Add(GetT(++tCount));
}
else
{
result.Add(item);
}
}
line = line with
{
FullClass = line.FullClass with
{
GenericParameterTypes = result,
RawGenericParameterTypes = rawResult
},
};
return Task.FromResult(line);
}
private string GetT(int order)
{
if (order == 1)
{
return "T";
}
return $"T{order}";
}
}