diff --git a/src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs b/src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs index fc4e93d1..461194ea 100644 --- a/src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs +++ b/src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs @@ -329,10 +329,8 @@ private IEnumerable DeclareFriendlyOverloads(MethodDefi leadingStatements.Add( LocalDeclarationStatement(VariableDeclaration(elementType) .AddVariables(VariableDeclarator(localName.Identifier).WithInitializer( - EqualsValueClause(ConditionalExpression( - MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, origName, IdentifierName("HasValue")), - MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, origName, IdentifierName("Value")), - DefaultExpression(elementType))))))); + EqualsValueClause( + BinaryExpression(SyntaxKind.CoalesceExpression, origName, DefaultExpression(elementType))))))); arguments[param.SequenceNumber - 1] = Argument(ConditionalExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, origName, IdentifierName("HasValue")), PrefixUnaryExpression(SyntaxKind.AddressOfExpression, localName), @@ -461,10 +459,8 @@ private IEnumerable DeclareFriendlyOverloads(MethodDefi leadingStatements.Add( LocalDeclarationStatement(VariableDeclaration(externParam.Type) .AddVariables(VariableDeclarator(localName.Identifier).WithInitializer( - EqualsValueClause(ConditionalExpression( - MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, origName, IdentifierName("HasValue")), - MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, origName, IdentifierName("Value")), - DefaultExpression(externParam.Type))))))); + EqualsValueClause( + BinaryExpression(SyntaxKind.CoalesceExpression, origName, DefaultExpression(externParam.Type))))))); // We can't pass in null, but we can be fancy to achieve the same effect. // Unsafe.NullRef() or Unsafe.AsRef(null), depending on what's available.