Skip to content

Commit 6c31d40

Browse files
Don't generate default paramters for non-string null values
1 parent 694e081 commit 6c31d40

1 file changed

Lines changed: 34 additions & 41 deletions

File tree

Unity/Assets/NativeScript/Editor/GenerateBindings.cs

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11667,56 +11667,49 @@ static void AppendCppParameterDeclaration(
1166711667
}
1166811668
output.Append("Plugin::NullString");
1166911669
}
11670-
else if (object.ReferenceEquals(param.DefaultValue, null))
11670+
else if (param.DefaultValue is bool)
1167111671
{
11672-
output.Append("nullptr");
11672+
bool val = (bool)param.DefaultValue;
11673+
output.Append(val ? "true" : "false");
11674+
}
11675+
else if (param.DefaultValue is char)
11676+
{
11677+
char val = (char)param.DefaultValue;
11678+
output.Append('\'');
11679+
output.Append(val);
11680+
output.Append('\'');
11681+
}
11682+
else if ((param.DefaultValue is sbyte) ||
11683+
(param.DefaultValue is byte) ||
11684+
(param.DefaultValue is short) ||
11685+
(param.DefaultValue is ushort) ||
11686+
(param.DefaultValue is int) ||
11687+
(param.DefaultValue is uint) ||
11688+
(param.DefaultValue is long) ||
11689+
(param.DefaultValue is ulong))
11690+
{
11691+
output.Append(param.DefaultValue);
1167311692
}
1167411693
else
1167511694
{
11676-
if ((param.DefaultValue is sbyte) ||
11677-
(param.DefaultValue is byte) ||
11678-
(param.DefaultValue is short) ||
11679-
(param.DefaultValue is ushort) ||
11680-
(param.DefaultValue is int) ||
11681-
(param.DefaultValue is uint) ||
11682-
(param.DefaultValue is long) ||
11683-
(param.DefaultValue is ulong))
11695+
Type type = param.DefaultValue.GetType();
11696+
if (type.IsEnum)
1168411697
{
11698+
AppendCppTypeName(
11699+
type,
11700+
output);
11701+
output.Append("::");
1168511702
output.Append(param.DefaultValue);
1168611703
}
11687-
else if (param.DefaultValue is bool)
11688-
{
11689-
bool val = (bool)param.DefaultValue;
11690-
output.Append(val ? "true" : "false");
11691-
}
11692-
else if (param.DefaultValue is char)
11693-
{
11694-
char val = (char)param.DefaultValue;
11695-
output.Append('\'');
11696-
output.Append(val);
11697-
output.Append('\'');
11698-
}
1169911704
else
1170011705
{
11701-
Type type = param.DefaultValue.GetType();
11702-
if (type.IsEnum)
11703-
{
11704-
AppendCppTypeName(
11705-
type,
11706-
output);
11707-
output.Append("::");
11708-
output.Append(param.DefaultValue);
11709-
}
11710-
else
11711-
{
11712-
StringBuilder error = new StringBuilder();
11713-
error.Append("Default parameter type (");
11714-
AppendCsharpTypeName(
11715-
param.DefaultValue.GetType(),
11716-
error);
11717-
error.Append(") not supported");
11718-
throw new Exception(error.ToString());
11719-
}
11706+
StringBuilder error = new StringBuilder();
11707+
error.Append("Default parameter type (");
11708+
AppendCsharpTypeName(
11709+
param.DefaultValue.GetType(),
11710+
error);
11711+
error.Append(") not supported");
11712+
throw new Exception(error.ToString());
1172011713
}
1172111714
}
1172211715
}

0 commit comments

Comments
 (0)