1using System.CodeDom.Compiler;
3using Microsoft.CodeAnalysis;
7public class TypeExporter(INamedTypeSymbol symbol) : IExporter
9 public void GenerateUnmanagedCode(IndentedTextWriter source, IndentedTextWriter header)
14 header.WriteLine($
"namespace {symbol.ContainingNamespace.GetFullName()}");
15 header.WriteLine(
"{");
18 header.WriteLine($
"class {symbol.Name}");
19 header.WriteLine(
"{");
22 header.WriteLine(
"void* __this;");
26 header.WriteLine(
"public:");
29 var methods = symbol.GetMembers().OfType<IMethodSymbol>().Where(method => method.IsExported()).ToArray();
30 for (var i = 0; i < methods.Length; i++)
32 var method = methods[i];
40 new MethodExporter(method).GenerateUnmanagedCode(source, header);
44 header.WriteLine(
"};");
47 header.WriteLine(
"}");
50 public void GenerateManagedCode(IndentedTextWriter builder)
52 builder.WriteLine($
"namespace {symbol.ContainingNamespace.GetManagedFullName()}");
53 builder.WriteLine(
"{");
56 var access = symbol.DeclaredAccessibility
switch
58 Accessibility.Private =>
"private",
59 Accessibility.ProtectedAndInternal =>
"private protected",
60 Accessibility.Protected =>
"protected",
61 Accessibility.Internal =>
"internal",
62 Accessibility.ProtectedOrInternal =>
"protected internal",
63 Accessibility.Public =>
"public",
64 _ =>
throw new ArgumentOutOfRangeException()
67 builder.WriteLine($
"{access} partial class {symbol.Name}");
68 builder.WriteLine(
"{");
71 var methods = symbol.GetMembers().OfType<IMethodSymbol>().Where(method => method.IsExported()).ToArray();
72 for (var i = 0; i < methods.Length; i++)
74 var method = methods[i];
80 IExporter.Create(method).GenerateManagedCode(builder);
84 builder.WriteLine(
"}");
87 builder.WriteLine(
"}");