diff --git a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs
index 974b5ce0..479934e2 100644
--- a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs
+++ b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs
@@ -18,7 +18,7 @@ namespace CppSharp.Generators.CLI
public override void Generate()
{
- GenerateStart();
+ OnStart(this);
WriteLine("#pragma once");
NewLine();
@@ -170,7 +170,7 @@ namespace CppSharp.Generators.CLI
public void GenerateFunctions(Namespace @namespace)
{
- WriteLine("public ref class {0}{1}", SafeIdentifier(Library.Name),
+ WriteLine("public ref class {0}{1}", SafeIdentifier(Options.OutputNamespace),
TranslationUnit.FileNameWithoutExtension);
WriteLine("{");
WriteLine("public:");
diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs
index 83e1fe92..db5208cc 100644
--- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs
+++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs
@@ -17,7 +17,7 @@ namespace CppSharp.Generators.CLI
public override void Generate()
{
- GenerateStart();
+ OnStart(this);
var file = Path.GetFileNameWithoutExtension(TranslationUnit.FileName).Replace('\\', '/');
@@ -35,7 +35,8 @@ namespace CppSharp.Generators.CLI
WriteLine("using namespace System;");
WriteLine("using namespace System::Runtime::InteropServices;");
- GenerateAfterNamespaces();
+
+ OnNamespaces(this);
NewLine();
GenerateDeclarations();
diff --git a/src/Generator/Generators/CLI/CLITextTemplate.cs b/src/Generator/Generators/CLI/CLITextTemplate.cs
index a5d2fc59..c8171490 100644
--- a/src/Generator/Generators/CLI/CLITextTemplate.cs
+++ b/src/Generator/Generators/CLI/CLITextTemplate.cs
@@ -27,6 +27,18 @@ namespace CppSharp.Generators.CLI
protected const string DefaultIndent = " ";
protected const uint MaxIndent = 80;
+ public delegate void GenerateTextDelegate(CLITextTemplate gen);
+
+ ///
+ /// Called when the generation is starting.
+ ///
+ public GenerateTextDelegate OnStart = delegate { };
+
+ ///
+ /// Called when generating namespaces.
+ ///
+ public GenerateTextDelegate OnNamespaces = delegate { };
+
public CLITypePrinter TypePrinter { get; set; }
public ISet Includes;
@@ -50,30 +62,6 @@ namespace CppSharp.Generators.CLI
return string.Format("{0}", decl.QualifiedName);
}
- public void GenerateStart()
- {
- if (Transform == null)
- {
- WriteLine("//----------------------------------------------------------------------------");
- WriteLine("// This is autogenerated code by cxxi-generator.");
- WriteLine("// Do not edit this file or all your changes will be lost after re-generation.");
- WriteLine("//----------------------------------------------------------------------------");
-
- if (FileExtension == "cpp")
- WriteLine(@"#include ""../interop.h"" // marshalString");
- }
- else
- {
- Transform.GenerateStart(this);
- }
- }
-
- public void GenerateAfterNamespaces()
- {
- if (Transform != null)
- Transform.GenerateAfterNamespaces(this);
- }
-
public void GenerateSummary(string comment)
{
if (string.IsNullOrWhiteSpace(comment))
diff --git a/src/Generator/Library.cs b/src/Generator/Library.cs
index 3e39a1c3..0ecdddfd 100644
--- a/src/Generator/Library.cs
+++ b/src/Generator/Library.cs
@@ -38,18 +38,6 @@ namespace CppSharp
///
///
void SetupPasses(Driver driver, PassBuilder passes);
-
- ///
- /// Called to generate text at the start of the text template.
- ///
- ///
- void GenerateStart(TextTemplate template);
-
- ///
- /// Called to generate text after the generation of namespaces.
- ///
- ///
- void GenerateAfterNamespaces(TextTemplate template);
}
public static class LibraryHelpers