@@ -924,25 +924,30 @@ public override async Task<CSharpSyntaxNode> VisitParameter(VBSyntax.ParameterSy
924924
925925 EqualsValueClauseSyntax @default = null ;
926926 if ( node . Default != null ) {
927- if ( node . Default . Value is VBSyntax . LiteralExpressionSyntax les && les . Token . Value is DateTime dt ) {
928- var dateTimeAsLongCsLiteral = LiteralConversions . GetLiteralExpression ( dt . Ticks , dt . Ticks + "L" ) ;
929- var dateTimeArg = CommonConversions . CreateAttributeArgumentList ( SyntaxFactory . AttributeArgument ( dateTimeAsLongCsLiteral ) ) ;
930- _extraUsingDirectives . Add ( "System.Runtime.InteropServices" ) ;
931- _extraUsingDirectives . Add ( "System.Runtime.CompilerServices" ) ;
932- var optionalDateTimeAttributes = new [ ] {
933- SyntaxFactory . Attribute ( SyntaxFactory . ParseName ( "Optional" ) ) ,
934- SyntaxFactory . Attribute ( SyntaxFactory . ParseName ( "DateTimeConstant" ) , dateTimeArg )
927+ var defaultValue = node . Default . Value . SkipParens ( ) ;
928+ if ( _semanticModel . GetTypeInfo ( defaultValue ) . Type ? . SpecialType == SpecialType . System_DateTime ) {
929+ var constant = _semanticModel . GetConstantValue ( defaultValue ) ;
930+ if ( constant . HasValue && constant . Value is DateTime dt ) {
931+ var dateTimeAsLongCsLiteral = CommonConversions . Literal ( dt . Ticks )
932+ . WithTrailingTrivia ( SyntaxFactory . ParseTrailingTrivia ( $ "/* { defaultValue } */") ) ;
933+ var dateTimeArg = CommonConversions . CreateAttributeArgumentList ( SyntaxFactory . AttributeArgument ( dateTimeAsLongCsLiteral ) ) ;
934+ _extraUsingDirectives . Add ( "System.Runtime.InteropServices" ) ;
935+ _extraUsingDirectives . Add ( "System.Runtime.CompilerServices" ) ;
936+ var optionalDateTimeAttributes = new [ ] {
937+ SyntaxFactory . Attribute ( SyntaxFactory . IdentifierName ( "Optional" ) ) ,
938+ SyntaxFactory . Attribute ( SyntaxFactory . IdentifierName ( "DateTimeConstant" ) , dateTimeArg )
935939 } ;
936- attributes . Insert ( 0 ,
937- SyntaxFactory . AttributeList ( SyntaxFactory . SeparatedList ( optionalDateTimeAttributes ) ) ) ;
940+ attributes . Insert ( 0 ,
941+ SyntaxFactory . AttributeList ( SyntaxFactory . SeparatedList ( optionalDateTimeAttributes ) ) ) ;
942+ }
938943 } else if ( node . Modifiers . Any ( m => m . IsKind ( VBasic . SyntaxKind . ByRefKeyword ) ) ) {
939944 var defaultExpression = ( ExpressionSyntax ) await node . Default . Value . AcceptAsync ( TriviaConvertingExpressionVisitor ) ;
940945 var arg = CommonConversions . CreateAttributeArgumentList ( SyntaxFactory . AttributeArgument ( defaultExpression ) ) ;
941946 _extraUsingDirectives . Add ( "System.Runtime.InteropServices" ) ;
942947 _extraUsingDirectives . Add ( "System.Runtime.CompilerServices" ) ;
943948 var optionalAttributes = new [ ] {
944- SyntaxFactory . Attribute ( SyntaxFactory . ParseName ( "Optional" ) ) ,
945- SyntaxFactory . Attribute ( SyntaxFactory . ParseName ( "DefaultParameterValue" ) , arg )
949+ SyntaxFactory . Attribute ( SyntaxFactory . IdentifierName ( "Optional" ) ) ,
950+ SyntaxFactory . Attribute ( SyntaxFactory . IdentifierName ( "DefaultParameterValue" ) , arg )
946951 } ;
947952 attributes . Insert ( 0 ,
948953 SyntaxFactory . AttributeList ( SyntaxFactory . SeparatedList ( optionalAttributes ) ) ) ;
0 commit comments