|
7 | 7 | using Microsoft.CodeAnalysis;
|
8 | 8 | using Microsoft.CodeAnalysis.CSharp;
|
9 | 9 | using Microsoft.CodeAnalysis.CSharp.Syntax;
|
| 10 | +using SyntaxFactory = Microsoft.CodeAnalysis.CSharp.SyntaxFactory; |
10 | 11 | using VBSyntax = Microsoft.CodeAnalysis.VisualBasic.Syntax;
|
11 | 12 | using VBasic = Microsoft.CodeAnalysis.VisualBasic;
|
12 | 13 | using SyntaxToken = Microsoft.CodeAnalysis.SyntaxToken;
|
@@ -821,17 +822,32 @@ public override CSharpSyntaxNode VisitParameter(VBSyntax.ParameterSyntax node)
|
821 | 822 | returnType = arrayType.WithElementType(SyntaxFactory.NullableType(arrayType.ElementType));
|
822 | 823 | }
|
823 | 824 | }
|
824 |
| - EqualsValueClauseSyntax @default = null; |
825 |
| - if (node.Default != null) { |
826 |
| - @default = SyntaxFactory.EqualsValueClause((ExpressionSyntax)node.Default?.Value.Accept(TriviaConvertingVisitor)); |
827 |
| - } |
| 825 | + |
828 | 826 | var attributes = node.AttributeLists.SelectMany(ConvertAttribute).ToList();
|
829 | 827 | int outAttributeIndex = attributes.FindIndex(a => a.Attributes.Single().Name.ToString() == "Out");
|
830 | 828 | var modifiers = CommonConversions.ConvertModifiers(node.Modifiers, TokenContext.Local);
|
831 | 829 | if (outAttributeIndex > -1) {
|
832 | 830 | attributes.RemoveAt(outAttributeIndex);
|
833 | 831 | modifiers = modifiers.Replace(SyntaxFactory.Token(SyntaxKind.RefKeyword), SyntaxFactory.Token(SyntaxKind.OutKeyword));
|
834 | 832 | }
|
| 833 | + |
| 834 | + EqualsValueClauseSyntax @default = null; |
| 835 | + if (node.Default != null) { |
| 836 | + if (node.Default.Value is VBSyntax.LiteralExpressionSyntax les && les.Token.Value is DateTime dt) |
| 837 | + { |
| 838 | + var dateTimeAsLongCsLiteral = CommonConversions.GetLiteralExpression(dt.Ticks, dt.Ticks + "L"); |
| 839 | + var dateTimeArg = CommonConversions.CreateAttributeArgumentList(SyntaxFactory.AttributeArgument(dateTimeAsLongCsLiteral)); |
| 840 | + var optionalDateTimeAttributes = new[] { |
| 841 | + SyntaxFactory.Attribute(SyntaxFactory.ParseName("System.Runtime.InteropServices.Optional")), |
| 842 | + SyntaxFactory.Attribute(SyntaxFactory.ParseName("System.Runtime.CompilerServices.DateTimeConstant"), dateTimeArg) |
| 843 | + }; |
| 844 | + attributes.Insert(0, |
| 845 | + SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList(optionalDateTimeAttributes))); |
| 846 | + } else { |
| 847 | + @default = SyntaxFactory.EqualsValueClause( |
| 848 | + (ExpressionSyntax)node.Default.Value.Accept(TriviaConvertingVisitor)); |
| 849 | + } |
| 850 | + } |
835 | 851 |
|
836 | 852 | if (node.Parent.Parent is VBSyntax.MethodStatementSyntax mss
|
837 | 853 | && mss.AttributeLists.Any(HasExtensionAttribute) && node.Parent.ChildNodes().First() == node) {
|
|
0 commit comments