From d340de3afae5d91c546f4994ceab40c5c7fe3d98 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Tue, 14 Feb 2017 23:40:41 +0000 Subject: [PATCH] Extract current module as read-only property to CodeGenerator.Module. --- src/Generator/Generators/CSharp/CSharpSources.cs | 15 ++++++--------- src/Generator/Generators/CodeGenerator.cs | 3 +++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 686396fc..bacafd7f 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -149,17 +149,14 @@ namespace CppSharp.Generators.CSharp { GenerateHeader(); - var module = TranslationUnits.Count == 0 ? - Context.Options.SystemModule : TranslationUnit.Module; - PushBlock(CSharpBlockKind.Usings); WriteLine("using System;"); WriteLine("using System.Runtime.InteropServices;"); WriteLine("using System.Security;"); - var internalsVisibleTo = (from m in Options.Modules - where m.Dependencies.Contains(module) - select m.LibraryName).ToList(); + var internalsVisibleTo = from m in Options.Modules + where m.Dependencies.Contains(Module) + select m.LibraryName; if (internalsVisibleTo.Any()) WriteLine("using System.Runtime.CompilerServices;"); @@ -173,17 +170,17 @@ namespace CppSharp.Generators.CSharp if (internalsVisibleTo.Any()) NewLine(); - if (!string.IsNullOrEmpty(module.OutputNamespace)) + if (!string.IsNullOrEmpty(Module.OutputNamespace)) { PushBlock(CSharpBlockKind.Namespace); - WriteLine("namespace {0}", module.OutputNamespace); + WriteLine("namespace {0}", Module.OutputNamespace); WriteStartBraceIndent(); } foreach (var unit in TranslationUnits) unit.Visit(this); - if (!string.IsNullOrEmpty(module.OutputNamespace)) + if (!string.IsNullOrEmpty(Module.OutputNamespace)) { WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock); diff --git a/src/Generator/Generators/CodeGenerator.cs b/src/Generator/Generators/CodeGenerator.cs index 5d053c6c..4a029439 100644 --- a/src/Generator/Generators/CodeGenerator.cs +++ b/src/Generator/Generators/CodeGenerator.cs @@ -14,6 +14,9 @@ namespace CppSharp.Generators public TranslationUnit TranslationUnit => TranslationUnits[0]; + public Module Module => TranslationUnits.Count == 0 ? + Context.Options.SystemModule : TranslationUnit.Module; + public abstract string FileExtension { get; } protected CodeGenerator(BindingContext context, TranslationUnit unit)