Browse Source

Extract the C# class constructor generation code to its own method.

pull/1/head
triton 12 years ago
parent
commit
b690aa9326
  1. 27
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

27
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -819,19 +819,9 @@ namespace Cxxi.Generators.CSharp
if (@class.IsRefType) if (@class.IsRefType)
{ {
if (method.Kind == CXXMethodKind.Constructor) if (method.IsConstructor)
{ {
if (!@class.IsAbstract) GenerateClassConstructor(method, @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(");");
}
} }
else else
{ {
@ -849,6 +839,19 @@ namespace Cxxi.Generators.CSharp
WriteCloseBraceIndent(); 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) private void GenerateValueTypeConstructorCall(Method method, Class @class)
{ {
var names = new List<string>(); var names = new List<string>();

Loading…
Cancel
Save