Skip to content

Commit

Permalink
autogenerate different getter code for strings and wide strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jetha Chan committed Dec 12, 2016
1 parent d5a2af9 commit 6f47d89
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions CodeGenDom/NativeCodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,26 @@ private static void GeneratePropertyDefinition(StringBuilder sb, NativeClassInfo
WriteLine(sb, " {0}* instance = reinterpret_cast<{0}*>(instanceId);", classInfo.NativeName);
WriteLine(sb, " static {0} localData;", info.NativeType);
WriteLine(sb, " localData = instance->Get{0}();", info.NativeName);
WriteLine(sb, " *data = (void*)&localData;");
WriteLine(sb, " *size = sizeof(localData);");

// need special handling for strings and wide strings here,
// or you'll end up trying to marshal the memory address
// instead of the contents into a managed string downstream
switch(info.NativeType)
{
case "wchar_t*":
WriteLine(sb, " *data = (void*)localData;");
WriteLine(sb, " *size = wcslen(localData);");
break;
case "char*":
WriteLine(sb, " *data = (void*)localData;");
WriteLine(sb, " *size = strlen(localData);");
break;

default:
WriteLine(sb, " *data = (void*)&localData;");
WriteLine(sb, " *size = sizeof(localData);");
break;
}
WriteLine(sb, "}}");
}
}
Expand Down

0 comments on commit 6f47d89

Please sign in to comment.