Browse Source

Refactored the variable wrapping code to work with pointers.

pull/1/head
triton 12 years ago
parent
commit
6d8af9776f
  1. 31
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

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

@ -592,15 +592,8 @@ namespace CppSharp.Generators.CSharp @@ -592,15 +592,8 @@ namespace CppSharp.Generators.CSharp
Setter
}
private string GetPropertyLocation<T>(T decl, PropertyMethodKind kind,
out bool isRefClass) where T : Declaration, ITypedDecl
private string GetVariableLocation(Variable @var)
{
isRefClass = false;
if (decl is Variable)
{
var @var = decl as Variable;
string symbol;
if (!FindMangledDeclSymbol(@var, out symbol))
return string.Empty;
@ -612,9 +605,6 @@ namespace CppSharp.Generators.CSharp @@ -612,9 +605,6 @@ namespace CppSharp.Generators.CSharp
Path.GetFileNameWithoutExtension(library.FileName), symbol);
}
throw new NotSupportedException();
}
private void GeneratePropertySetter<T>(T decl, Class @class)
where T : Declaration, ITypedDecl
{
@ -699,17 +689,24 @@ namespace CppSharp.Generators.CSharp @@ -699,17 +689,24 @@ namespace CppSharp.Generators.CSharp
WriteLine("return {0};", marshal.Context.Return);
}
else
else if (decl is Variable)
{
bool isRefClass;
@return = GetPropertyLocation(decl, PropertyMethodKind.Getter,
out isRefClass);
var @var = decl as Variable;
var location = GetVariableLocation(@var);
var typePrinter = TypePrinter as CSharpTypePrinter;
typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
WriteLine("var {0} = ({1}*){2};", Helpers.GeneratedIdentifier("ptr"),
@var.Type, location);
typePrinter.PopContext();
var ctx = new CSharpMarshalContext(Driver)
{
ArgName = decl.Name,
ReturnVarName = @return,
ReturnType = decl.QualifiedType
ReturnVarName = "*" + Helpers.GeneratedIdentifier("ptr"),
ReturnType = new QualifiedType(var.Type)
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);

Loading…
Cancel
Save