-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInterceptorAttributeEmitter.cs
More file actions
39 lines (30 loc) · 1.22 KB
/
InterceptorAttributeEmitter.cs
File metadata and controls
39 lines (30 loc) · 1.22 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
using System.CodeDom.Compiler;
namespace AutoLoggerMessageGenerator.Emitters;
internal static class InterceptorAttributeEmitter
{
public static string Emit()
{
using var sb = new IndentedTextWriter(new StringWriter());
sb.WriteLine(Constants.GeneratedFileHeader);
sb.WriteLine();
sb.WriteLine($"namespace {Constants.InterceptorNamespace}");
sb.WriteLine('{');
sb.Indent++;
sb.WriteLine(Constants.GeneratedCodeAttribute);
sb.WriteLine(Constants.EditorNotBrowsableAttribute);
sb.WriteLine("[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]");
sb.WriteLine($"internal sealed class {Constants.InterceptorAttributeName} : Attribute");
sb.WriteLine('{');
sb.Indent++;
#if PATH_BASED_INTERCEPTORS
sb.WriteLine($"public {Constants.InterceptorAttributeName}(string filePath, int line, int character) {{}}");
#elif HASH_BASED_INTERCEPTORS
sb.WriteLine($"public {Constants.InterceptorAttributeName}(int version, string data) {{}}");
#endif
sb.Indent--;
sb.WriteLine('}');
sb.Indent--;
sb.WriteLine('}');
return sb.InnerWriter.ToString()!;
}
}