From b690aa93264a9ab27db984772ecc487765b3fa26 Mon Sep 17 00:00:00 2001 From: triton Date: Mon, 6 May 2013 02:42:46 +0100 Subject: [PATCH] Extract the C# class constructor generation code to its own method. --- .../Generators/CSharp/CSharpTextTemplate.cs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 3130fadb..8ef3f8b2 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -819,19 +819,9 @@ namespace Cxxi.Generators.CSharp if (@class.IsRefType) { - if (method.Kind == CXXMethodKind.Constructor) + if (method.IsConstructor) { - if (!@class.IsAbstract) - { - var @params = GenerateFunctionParamsMarshal(method.Parameters, method); - - WriteLine("Instance = Marshal.AllocHGlobal({0});", @class.Layout.Size); - Write("Internal.{0}(Instance", GetFunctionNativeIdentifier(method, @class)); - if (@params.Any()) - Write(", "); - GenerateFunctionParams(@params); - WriteLine(");"); - } + GenerateClassConstructor(method, @class); } else { @@ -849,6 +839,19 @@ namespace Cxxi.Generators.CSharp WriteCloseBraceIndent(); } + + private void GenerateClassConstructor(Method method, Class @class) + { + var @params = GenerateFunctionParamsMarshal(method.Parameters, method); + + WriteLine("Instance = Marshal.AllocHGlobal({0});", @class.Layout.Size); + Write("Internal.{0}(Instance", GetFunctionNativeIdentifier(method, @class)); + if (@params.Any()) + Write(", "); + GenerateFunctionParams(@params); + WriteLine(");"); + } + private void GenerateValueTypeConstructorCall(Method method, Class @class) { var names = new List();