forked from 47-studio-org/PostSharp.Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFormatter.cs
52 lines (47 loc) · 1.3 KB
/
Formatter.cs
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
using PostSharp.Aspects;
using System;
using System.Text;
namespace PostSharp.Samples.ExceptionHandling
{
/// <summary>
/// Helps creating a string out of a method call context.
/// </summary>
internal static class Formatter
{
public static void AppendTypeName(StringBuilder stringBuilder, Type declaringType)
{
stringBuilder.Append(declaringType.FullName);
if (declaringType.IsGenericType)
{
var genericArguments = declaringType.GetGenericArguments();
AppendGenericArguments(stringBuilder, genericArguments);
}
}
public static void AppendGenericArguments(StringBuilder stringBuilder, Type[] genericArguments)
{
stringBuilder.Append('<');
for (var i = 0; i < genericArguments.Length; i++)
{
if (i > 0)
{
stringBuilder.Append(", ");
}
stringBuilder.Append(genericArguments[i].Name);
}
stringBuilder.Append('>');
}
public static void AppendArguments(StringBuilder stringBuilder, Arguments arguments)
{
stringBuilder.Append('(');
for (var i = 0; i < arguments.Count; i++)
{
if (i > 0)
{
stringBuilder.Append(", ");
}
stringBuilder.Append(arguments[i]);
}
stringBuilder.Append(')');
}
}
}