Skip to content

Commit 1a25f39

Browse files
Changed the site to add cast.
1 parent 08d8a1c commit 1a25f39

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Generator/Generators/CSharp/CSharpTextTemplate.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2202,9 +2202,11 @@ public void GenerateMethod(Method method, Class @class)
22022202

22032203
private string OverloadParamNameWithDefValue(Parameter p, ref int index)
22042204
{
2205+
Class @class;
22052206
return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue
22062207
? "ref param" + index++
2207-
: ExpressionPrinter.VisitExpression(p.DefaultArgument).Value;
2208+
: (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++
2209+
: ExpressionPrinter.VisitExpression(p.DefaultArgument).Value);
22082210
}
22092211

22102212
private void GenerateOverloadCall(Function function)
@@ -2221,6 +2223,14 @@ private void GenerateOverloadCall(Function function)
22212223
WriteLine("{0} param{1} = {2};", pointeeType, j++,
22222224
primitiveType == PrimitiveType.Bool ? "false" : "0");
22232225
}
2226+
Class @class;
2227+
if(parameter.Kind == ParameterKind.Regular && parameter.Ignore &&
2228+
parameter.Type.Desugar().TryGetClass(out @class) && @class.IsInterface &&
2229+
parameter.HasDefaultValue)
2230+
{
2231+
WriteLine("var param{0} = ({1}) {2};", j++, @class.OriginalClass.OriginalName,
2232+
ExpressionPrinter.VisitExpression(parameter.DefaultArgument).Value);
2233+
}
22242234
}
22252235

22262236
GenerateManagedCall(function);

src/Generator/Passes/HandleDefaultParamValuesPass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private bool CheckForEnumValue(Type desugared, Statement statement,
243243
if (enumItem != null)
244244
{
245245
result = string.Format("{0}{1}.{2}",
246-
desugared.IsPrimitiveType() ? "(int) " : "(" + desugared.CSharpType(new CSharpTypePrinter(Driver)) + ") ",
246+
desugared.IsPrimitiveType() ? "(int) " : string.Empty,
247247
new CSharpTypePrinter(Driver).VisitEnumDecl(
248248
(Enumeration) enumItem.Namespace), enumItem.Name);
249249
return true;

0 commit comments

Comments
 (0)