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

Loading…
Cancel
Save