@@ -726,8 +726,7 @@ await a.AcceptAsync<AccessorDeclarationSyntax>(TriviaConvertingDeclarationVisito
726726 }
727727 if ( propSymbol . SetMethod != null ) {
728728 var setMethod = await CreateMethodDeclarationSyntaxAsync ( node . ParameterList , SetMethodId ( node ) , true ) ;
729- var valueParam = SyntaxFactory . Parameter ( CommonConversions . CsEscapedIdentifier ( "value" ) ) . WithType ( rawType ) ;
730- setMethod = setMethod . AddParameterListParameters ( valueParam ) ;
729+ setMethod = AddValueSetParameter ( propSymbol , setMethod , rawType ) ;
731730 methodDeclarationSyntaxs . Add ( setMethod ) ;
732731 }
733732 _additionalDeclarations . Add ( node , methodDeclarationSyntaxs . Skip ( 1 ) . ToArray ( ) ) ;
@@ -905,7 +904,7 @@ await asClause.Type.AcceptAsync<TypeSyntax>(_triviaConvertingExpressionVisitor,
905904
906905 if ( await ShouldConvertAsParameterizedPropertyAsync ( containingPropertyStmt ) ) {
907906 var setMethod = await CreateMethodDeclarationSyntax ( containingPropertyStmt ? . ParameterList , true ) ;
908- return setMethod . AddParameterListParameters ( SyntaxFactory . Parameter ( CommonConversions . CsEscapedIdentifier ( "value" ) ) . WithType ( returnType ) ) ;
907+ return AddValueSetParameter ( declaredPropSymbol , setMethod , returnType ) ;
909908 }
910909 break ;
911910 case VBasic . SyntaxKind . AddHandlerAccessorBlock :
@@ -939,6 +938,13 @@ async Task<MethodDeclarationSyntax> CreateMethodDeclarationSyntax(VBSyntax.Param
939938 }
940939 }
941940
941+ private static MethodDeclarationSyntax AddValueSetParameter ( IPropertySymbol declaredPropSymbol , MethodDeclarationSyntax setMethod , TypeSyntax returnType )
942+ {
943+ var valueParam = SyntaxFactory . Parameter ( CommonConversions . CsEscapedIdentifier ( "value" ) ) . WithType ( returnType ) ;
944+ if ( declaredPropSymbol ? . Parameters . Any ( p => p . IsOptional ) == true ) valueParam = valueParam . WithDefault ( SyntaxFactory . EqualsValueClause ( ValidSyntaxFactory . DefaultExpression ) ) ;
945+ return setMethod . AddParameterListParameters ( valueParam ) ;
946+ }
947+
942948 private static string SetMethodId ( VBSyntax . PropertyStatementSyntax containingPropertyStmt )
943949 {
944950 return $ "set_{ ( containingPropertyStmt . Identifier . Text ) } ";
0 commit comments