Browse Source

Wrap the Instance identifier name into its own property and change the code to use it.

pull/1/head
triton 12 years ago
parent
commit
e57e22e3b8
  1. 5
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 27
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

5
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -428,12 +428,13 @@ namespace CppSharp.Generators.CSharp
&& method.Conversion == MethodConversionKind.FunctionToInstanceMethod && method.Conversion == MethodConversionKind.FunctionToInstanceMethod
&& Context.ParameterIndex == 0) && Context.ParameterIndex == 0)
{ {
Context.Return.Write("Instance"); Context.Return.Write("{0}", Helpers.InstanceIdentifier);
return; return;
} }
if (Context.Parameter.Type.IsPointer()) if (Context.Parameter.Type.IsPointer())
Context.Return.Write("{0}.Instance", Context.Parameter.Name); Context.Return.Write("{0}.{1}", Context.Parameter.Name,
Helpers.InstanceIdentifier);
else else
Context.Return.Write("{0}", Context.Parameter.Name); Context.Return.Write("{0}", Context.Parameter.Name);
} }

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

@ -54,6 +54,11 @@ namespace CppSharp.Generators.CSharp
return "Winapi"; return "Winapi";
} }
public static string InstanceIdentifier
{
get { return GeneratedIdentifier("Instance"); }
}
} }
public class CSharpTextTemplate : TextTemplate public class CSharpTextTemplate : TextTemplate
@ -253,7 +258,8 @@ namespace CppSharp.Generators.CSharp
if (ShouldGenerateClassNativeField(@class)) if (ShouldGenerateClassNativeField(@class))
{ {
NewLineIfNeeded(); NewLineIfNeeded();
WriteLine("public System.IntPtr Instance { get; protected set; }"); WriteLine("public System.IntPtr {0} {{ get; protected set; }}",
Helpers.InstanceIdentifier);
NeedNewLine(); NeedNewLine();
} }
@ -546,7 +552,7 @@ namespace CppSharp.Generators.CSharp
{ {
var field = decl as Field; var field = decl as Field;
var location = GetFieldLocation(field, "Instance", var location = GetFieldLocation(field, Helpers.InstanceIdentifier,
CSharpTypePrinterContextKind.Managed, out isRefClass); CSharpTypePrinterContextKind.Managed, out isRefClass);
if (isRefClass && kind == PropertyMethodKind.Getter) if (isRefClass && kind == PropertyMethodKind.Getter)
@ -782,7 +788,7 @@ namespace CppSharp.Generators.CSharp
WriteStartBraceIndent(); WriteStartBraceIndent();
if (ShouldGenerateClassNativeField(@class)) if (ShouldGenerateClassNativeField(@class))
WriteLine("Marshal.FreeHGlobal(Instance);"); WriteLine("Marshal.FreeHGlobal({0});", Helpers.InstanceIdentifier);
if (hasBaseClass) if (hasBaseClass)
WriteLine("base.Dispose(disposing);"); WriteLine("base.Dispose(disposing);");
@ -804,7 +810,7 @@ namespace CppSharp.Generators.CSharp
if (@class.IsRefType) if (@class.IsRefType)
{ {
if (ShouldGenerateClassNativeField(@class)) if (ShouldGenerateClassNativeField(@class))
WriteLine("Instance = native;"); WriteLine("{0} = native;", Helpers.InstanceIdentifier);
} }
else else
{ {
@ -940,8 +946,10 @@ namespace CppSharp.Generators.CSharp
{ {
var @params = GenerateFunctionParamsMarshal(method.Parameters, method); var @params = GenerateFunctionParamsMarshal(method.Parameters, method);
WriteLine("Instance = Marshal.AllocHGlobal({0});", @class.Layout.Size); WriteLine("{0} = Marshal.AllocHGlobal({1});", Helpers.InstanceIdentifier,
Write("Internal.{0}(Instance", GetFunctionNativeIdentifier(method, @class)); @class.Layout.Size);
Write("Internal.{0}({1}", GetFunctionNativeIdentifier(method, @class),
Helpers.InstanceIdentifier);
if (@params.Any()) if (@params.Any())
Write(", "); Write(", ");
GenerateFunctionParams(@params); GenerateFunctionParams(@params);
@ -1061,7 +1069,7 @@ namespace CppSharp.Generators.CSharp
if (needsInstance) if (needsInstance)
{ {
names.Insert(0, needsFixedThis ? string.Format("new System.IntPtr({0})", names.Insert(0, needsFixedThis ? string.Format("new System.IntPtr({0})",
GeneratedIdentifier("instance")) : "Instance"); GeneratedIdentifier("instance")) : Helpers.InstanceIdentifier);
} }
if (needsFixedThis) if (needsFixedThis)
@ -1119,8 +1127,9 @@ namespace CppSharp.Generators.CSharp
WriteLine("*({0}.Internal*) &ret = {1};", retClass.Name, WriteLine("*({0}.Internal*) &ret = {1};", retClass.Name,
GeneratedIdentifier("udt")); GeneratedIdentifier("udt"));
else else
WriteLine("*({0}.Internal*) ret.Instance.ToPointer() = {1};", WriteLine("*({0}.Internal*) ret.{1}.ToPointer() = {2};",
retClass.Name, GeneratedIdentifier("udt")); retClass.Name, Helpers.InstanceIdentifier,
GeneratedIdentifier("udt"));
WriteLine("return ret;"); WriteLine("return ret;");
} }

Loading…
Cancel
Save