1using Microsoft.CodeAnalysis;
7public readonly
struct TypeDefWriter(INamedTypeSymbol symbol) :
ICodeWriter
9 public IEnumerable<WorkspaceDiagnostic> WriteTo(CodeWriter w, CodeContext ctx)
11 if (!symbol.IsTarget())
16 var internals = symbol
20 .FirstOrDefault(type => type.GetFullName() ==
"MLLIF.Internal");
21 var freeDelegate = symbol
25 .FirstOrDefault(type => type.GetFullName() ==
"MLLIF.Internal.FreeDelegate");
26 if (internals is
null || freeDelegate is
null)
28 yield
return BindingDiagnostic.Error(ctx.Project, symbol,
"couldn't find embedded internals; is source generator added to project?");
32 w.WriteLine($
"{symbol.GetFullName("::
")}::~{symbol.Name}() {{");
36 static void (*__proxy)(void*) = nullptr;
38 ::s_get_function_pointer("{{internals.GetFullyQualifiedName()}}
", "{{internals.MetadataName}}
", "{{freeDelegate.GetFullyQualifiedName()}}
", nullptr, nullptr, reinterpret_cast<void**>(&__proxy));
50 .OfType<IMethodSymbol>()
51 .Where(SymbolExtension.IsTarget)
53 foreach (var method
in methods)
54 foreach (var diag
in new MethodDefWriter(method).WriteTo(w, ctx))
class BindingDiagnostic(WorkspaceDiagnosticKind kind, string message, Project project, Document? document)