From 0c22de2949e652876bb5c916fae8dcf72bc796ca Mon Sep 17 00:00:00 2001 From: triton Date: Sun, 26 May 2013 18:11:13 +0100 Subject: [PATCH] Added better support for generating global/namespace functions. --- .../Generators/CSharp/CSharpTextTemplate.cs | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 49411717..fdcb1104 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -199,13 +199,33 @@ namespace CppSharp.Generators.CSharp if (context.HasFunctions) { NewLineIfNeeded(); - WriteLine("public partial class {0}{1}", SafeIdentifier(Options.LibraryName), + WriteLine("public partial class {0}{1}", SafeIdentifier(Options.OutputNamespace), TranslationUnit.FileNameWithoutExtension); WriteStartBraceIndent(); - // Generate all the function declarations. + GenerateClassInternalHead(); + WriteStartBraceIndent(); + + // Generate all the internal function declarations. foreach (var function in context.Functions) + { + if (function.Ignore) continue; + + NewLineIfNeeded(); + GenerateInternalFunction(function); + NeedNewLine(); + } + + WriteCloseBraceIndent(); + + foreach (var function in context.Functions) + { + if (function.Ignore) continue; + + NewLineIfNeeded(); GenerateFunction(function); + NeedNewLine(); + } WriteCloseBraceIndent(); } @@ -911,6 +931,21 @@ namespace CppSharp.Generators.CSharp #region Methods / Functions + public void GenerateFunction(Function function) + { + GenerateDeclarationCommon(function); + + var functionName = GetFunctionIdentifier(function); + Write("public static {0} {1}(", function.ReturnType, functionName); + GenerateMethodParameters(function); + WriteLine(")"); + WriteStartBraceIndent(); + + GenerateInternalFunctionCall(function); + + WriteCloseBraceIndent(); + } + public void GenerateMethod(Method method, Class @class) { GenerateDeclarationCommon(method);