Browse Source

Removed parameters wrapped in v-table delegate hooks from the native to managed map.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/552/merge
Dimitar Dobrev 10 years ago
parent
commit
007fb4b57c
  1. 15
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 2
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

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

@ -61,6 +61,8 @@ namespace CppSharp.Generators.CSharp @@ -61,6 +61,8 @@ namespace CppSharp.Generators.CSharp
Context.MarshalToManaged = this;
}
public bool MarshalsParameter { get; set; }
public static string QualifiedIdentifier(Declaration decl)
{
var names = new List<string> { decl.Name };
@ -315,7 +317,8 @@ namespace CppSharp.Generators.CSharp @@ -315,7 +317,8 @@ namespace CppSharp.Generators.CSharp
{
var originalClass = @class.OriginalClass ?? @class;
var ret = Generator.GeneratedIdentifier("result") + Context.ParameterIndex;
Context.SupportBefore.WriteLine("{0} {1};", QualifiedIdentifier(@class), ret);
var qualifiedIdentifier = QualifiedIdentifier(@class);
Context.SupportBefore.WriteLine("{0} {1};", qualifiedIdentifier, ret);
Context.SupportBefore.WriteLine("if ({0} == IntPtr.Zero) {1} = {2};", Context.ReturnVarName, ret,
originalClass.IsRefType ? "null" : string.Format("new {0}()", qualifiedClass));
if (originalClass.IsRefType)
@ -323,13 +326,15 @@ namespace CppSharp.Generators.CSharp @@ -323,13 +326,15 @@ namespace CppSharp.Generators.CSharp
Context.SupportBefore.WriteLine(
"else if ({0}.NativeToManagedMap.ContainsKey({1}))", qualifiedClass, Context.ReturnVarName);
Context.SupportBefore.WriteLineIndent("{0} = ({1}) {2}.NativeToManagedMap[{3}];",
ret, QualifiedIdentifier(@class), qualifiedClass, Context.ReturnVarName);
ret, qualifiedIdentifier, qualifiedClass, Context.ReturnVarName);
var dtor = originalClass.Destructors.FirstOrDefault();
if (dtor != null && dtor.IsVirtual)
{
Context.SupportBefore.WriteLine("else {0}.NativeToManagedMap[{1}] = {2} = ({3}) {4}.{5}({1});",
qualifiedClass, Context.ReturnVarName, ret, QualifiedIdentifier(@class), qualifiedClass,
Helpers.CreateInstanceIdentifier, Context.ReturnVarName);
Context.SupportBefore.WriteLine("else {0}{1} = ({2}) {3}.{4}({5});",
MarshalsParameter
? string.Empty
: string.Format("{0}.NativeToManagedMap[{1}] = ", qualifiedClass, Context.ReturnVarName),
ret, qualifiedIdentifier, qualifiedClass, Helpers.CreateInstanceIdentifier, Context.ReturnVarName);
}
else
{

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

@ -1520,7 +1520,7 @@ namespace CppSharp.Generators.CSharp @@ -1520,7 +1520,7 @@ namespace CppSharp.Generators.CSharp
ParameterIndex = i
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx) { MarshalsParameter = true };
param.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))

Loading…
Cancel
Save