From e0bb3ec11fa52dd4238e7aa900a6ae91d377b53e Mon Sep 17 00:00:00 2001 From: GrahamTheCoder Date: Sat, 30 Mar 2024 11:35:42 +0000 Subject: [PATCH 1/9] Pass cancellation token --- CodeConverter/CSharp/ClashingMemberRenamer.cs | 6 +++--- CodeConverter/CSharp/VBToCSProjectContentsConverter.cs | 2 +- CodeConverter/Common/SymbolRenamer.cs | 2 +- CodeConverter/VB/CSToVBProjectContentsConverter.cs | 2 +- CodeConverter/VB/ClashingMemberRenamer.cs | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CodeConverter/CSharp/ClashingMemberRenamer.cs b/CodeConverter/CSharp/ClashingMemberRenamer.cs index 586701416..dbd7544b8 100644 --- a/CodeConverter/CSharp/ClashingMemberRenamer.cs +++ b/CodeConverter/CSharp/ClashingMemberRenamer.cs @@ -8,12 +8,12 @@ internal static class ClashingMemberRenamer /// Renames symbols in a VB project so that they don't clash with rules for C# member names, attempting to rename the least public ones first. /// See https://github.com/icsharpcode/CodeConverter/issues/420 /// - public static async Task RenameClashingSymbolsAsync(Project project) + public static async Task RenameClashingSymbolsAsync(Project project, CancellationToken cancellationToken) { - var compilation = await project.GetCompilationAsync(); + var compilation = await project.GetCompilationAsync(cancellationToken); var memberRenames = SymbolRenamer.GetNamespacesAndTypesInAssembly(project, compilation) .SelectMany(x => GetSymbolsWithNewNames(x, compilation)); - return await SymbolRenamer.PerformRenamesAsync(project, memberRenames.ToList()); + return await SymbolRenamer.PerformRenamesAsync(project, memberRenames.ToList(), cancellationToken); } private static IEnumerable<(ISymbol Original, string NewName)> GetSymbolsWithNewNames(INamespaceOrTypeSymbol containerSymbol, Compilation compilation) diff --git a/CodeConverter/CSharp/VBToCSProjectContentsConverter.cs b/CodeConverter/CSharp/VBToCSProjectContentsConverter.cs index 595f5ecd0..d6fd1126c 100644 --- a/CodeConverter/CSharp/VBToCSProjectContentsConverter.cs +++ b/CodeConverter/CSharp/VBToCSProjectContentsConverter.cs @@ -40,7 +40,7 @@ public VBToCSProjectContentsConverter(ConversionOptions conversionOptions, public async Task InitializeSourceAsync(Project project) { - project = await ClashingMemberRenamer.RenameClashingSymbolsAsync(project); + project = await ClashingMemberRenamer.RenameClashingSymbolsAsync(project, _cancellationToken); var cSharpCompilationOptions = CSharpCompiler.CreateCompilationOptions(); _convertedCsProject = project.ToProjectFromAnyOptions(cSharpCompilationOptions, CSharpCompiler.ParseOptions); _csharpReferenceProject = project.CreateReferenceOnlyProjectFromAnyOptions(cSharpCompilationOptions, CSharpCompiler.ParseOptions); diff --git a/CodeConverter/Common/SymbolRenamer.cs b/CodeConverter/Common/SymbolRenamer.cs index e81531d76..5ee789494 100644 --- a/CodeConverter/Common/SymbolRenamer.cs +++ b/CodeConverter/Common/SymbolRenamer.cs @@ -26,7 +26,7 @@ public static string GetName(ISymbol m) { return m.Name; } - public static async Task PerformRenamesAsync(Project project, IEnumerable<(ISymbol Original, string NewName)> symbolsWithNewNames) + public static async Task PerformRenamesAsync(Project project, IEnumerable<(ISymbol Original, string NewName)> symbolsWithNewNames, CancellationToken cancellationToken) { var solution = project.Solution; foreach (var (originalSymbol, newName) in symbolsWithNewNames.OrderByDescending(s => s.Original.DeclaringSyntaxReferences.Select(x => x.Span.End).Max())) { diff --git a/CodeConverter/VB/CSToVBProjectContentsConverter.cs b/CodeConverter/VB/CSToVBProjectContentsConverter.cs index 571443206..cd8fda793 100644 --- a/CodeConverter/VB/CSToVBProjectContentsConverter.cs +++ b/CodeConverter/VB/CSToVBProjectContentsConverter.cs @@ -45,7 +45,7 @@ public CSToVBProjectContentsConverter(ConversionOptions conversionOptions, IProg public async Task InitializeSourceAsync(Project project) { // TODO: Don't throw away solution-wide effects - write them to referencing files, and use in conversion of any other projects being converted at the same time. - project = await ClashingMemberRenamer.RenameClashingSymbolsAsync(project); + project = await ClashingMemberRenamer.RenameClashingSymbolsAsync(project, _cancellationToken); _convertedVbProject = project.ToProjectFromAnyOptions(_vbCompilationOptions, _vbParseOptions); _vbReferenceProject = project.CreateReferenceOnlyProjectFromAnyOptions(_vbCompilationOptions, _vbParseOptions); _vbViewOfCsSymbols = (VisualBasicCompilation)await _vbReferenceProject.GetCompilationAsync(_cancellationToken); diff --git a/CodeConverter/VB/ClashingMemberRenamer.cs b/CodeConverter/VB/ClashingMemberRenamer.cs index 00962cc9e..2648a5875 100644 --- a/CodeConverter/VB/ClashingMemberRenamer.cs +++ b/CodeConverter/VB/ClashingMemberRenamer.cs @@ -10,12 +10,12 @@ internal static class ClashingMemberRenamer /// Cases in different named scopes should be dealt with by . /// For names scoped within a type member, see . /// - public static async Task RenameClashingSymbolsAsync(Project project) + public static async Task RenameClashingSymbolsAsync(Project project, CancellationToken cancellationToken) { - var compilation = await project.GetCompilationAsync(); + var compilation = await project.GetCompilationAsync(cancellationToken); var memberRenames = SymbolRenamer.GetNamespacesAndTypesInAssembly(project, compilation) .SelectMany(x => GetSymbolsWithNewNames(x, compilation)); - return await SymbolRenamer.PerformRenamesAsync(project, memberRenames.ToList()); + return await SymbolRenamer.PerformRenamesAsync(project, memberRenames.ToList(), cancellationToken); } private static IEnumerable<(ISymbol Original, string NewName)> GetSymbolsWithNewNames(INamespaceOrTypeSymbol containerSymbol, Compilation compilation) From f9dc081748e5f49b455d7efd1ece84396dccd77a Mon Sep 17 00:00:00 2001 From: GrahamTheCoder Date: Sat, 30 Mar 2024 11:36:01 +0000 Subject: [PATCH 2/9] Use non-deprecated API --- CodeConverter/CSharp/CommonConversions.cs | 2 +- CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs | 2 +- CodeConverter/Common/SymbolRenamer.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CodeConverter/CSharp/CommonConversions.cs b/CodeConverter/CSharp/CommonConversions.cs index 4402d5a05..aa05a3a0c 100644 --- a/CodeConverter/CSharp/CommonConversions.cs +++ b/CodeConverter/CSharp/CommonConversions.cs @@ -569,7 +569,7 @@ public static CSSyntax.VariableDeclaratorSyntax CreateVariableDeclarator(string { if (operation is IPropertyReferenceOperation pro && pro.Arguments.Any() && !VisualBasicExtensions.IsDefault(pro.Property)) { - var isSetter = pro.Parent.Kind == OperationKind.SimpleAssignment && pro.Parent.Children.First() == pro; + var isSetter = pro.Parent.Kind == OperationKind.SimpleAssignment && pro.Parent.ChildOperations.First() == pro; var extraArg = isSetter ? await GetParameterizedSetterArgAsync(operation) : null; diff --git a/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs b/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs index cf41e9689..edd019226 100644 --- a/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs +++ b/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs @@ -164,7 +164,7 @@ private static async Task RenamePrefixAsync(Project project, string old for (var symbolToRename = await GetElementToRename(project); symbolToRename != null; symbolToRename = await GetElementToRename(project, toSkip)) { string newName = symbolToRename.Name.Replace(oldNamePrefix, newNamePrefix); try { - var renamedSolution = await Renamer.RenameSymbolAsync(project.Solution, symbolToRename, newName, project.Solution.Workspace.Options, cancellationToken); + var renamedSolution = await Renamer.RenameSymbolAsync(project.Solution, symbolToRename, new SymbolRenameOptions(), newName, cancellationToken); project = renamedSolution.GetProject(project.Id); } catch (Exception e) { toSkip++; diff --git a/CodeConverter/Common/SymbolRenamer.cs b/CodeConverter/Common/SymbolRenamer.cs index 5ee789494..3891a30b6 100644 --- a/CodeConverter/Common/SymbolRenamer.cs +++ b/CodeConverter/Common/SymbolRenamer.cs @@ -35,7 +35,7 @@ public static async Task PerformRenamesAsync(Project project, IEnumerab ISymbol currentDeclaration = SymbolFinder.FindSimilarSymbols(originalSymbol, compilation).FirstOrDefault(); if (currentDeclaration == null) continue; //Must have already renamed this symbol for a different reason - solution = await Renamer.RenameSymbolAsync(solution, currentDeclaration, newName, solution.Workspace.Options); + solution = await Renamer.RenameSymbolAsync(solution, currentDeclaration, new SymbolRenameOptions(), newName, cancellationToken); } return solution.GetProject(project.Id); From 9213b0ed47316f8317275795321c4c47da252e85 Mon Sep 17 00:00:00 2001 From: GrahamTheCoder Date: Sat, 30 Mar 2024 11:37:12 +0000 Subject: [PATCH 3/9] Upgrade to roslyn 4.6.0 (new min version: Visual Studio 2022 version 17.6 which is the previous LTS) --- CodeConverter/CodeConverter.csproj | 4 ++-- .../CodeConv.NetFramework.csproj | 8 ++++---- CommandLine/CodeConv/CodeConv.csproj | 8 ++++---- Func/Func.csproj | 12 ++++++------ Tests/Tests.csproj | 8 ++++---- Web/Web.csproj | 1 - 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/CodeConverter/CodeConverter.csproj b/CodeConverter/CodeConverter.csproj index 8a4f82b13..1c292b5d9 100644 --- a/CodeConverter/CodeConverter.csproj +++ b/CodeConverter/CodeConverter.csproj @@ -36,8 +36,8 @@ - - + + all diff --git a/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj b/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj index c5ec4d625..c67bca35f 100644 --- a/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj +++ b/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj @@ -10,11 +10,11 @@ - + - - - + + + diff --git a/CommandLine/CodeConv/CodeConv.csproj b/CommandLine/CodeConv/CodeConv.csproj index 05197601e..db838c8c3 100644 --- a/CommandLine/CodeConv/CodeConv.csproj +++ b/CommandLine/CodeConv/CodeConv.csproj @@ -31,11 +31,11 @@ - + - - - + + + all runtime; build; native; contentfiles; analyzers diff --git a/Func/Func.csproj b/Func/Func.csproj index 1dbc5fbcf..a7605188b 100644 --- a/Func/Func.csproj +++ b/Func/Func.csproj @@ -29,13 +29,13 @@ - + - - - - - + + + + + diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 647e04d44..8901c1bf4 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -36,10 +36,10 @@ - - - - + + + + diff --git a/Web/Web.csproj b/Web/Web.csproj index dc3a93a91..428c8acfb 100644 --- a/Web/Web.csproj +++ b/Web/Web.csproj @@ -20,7 +20,6 @@ - From 24a2932dcc227df8bf5ac71f70c45f15bcb4c234 Mon Sep 17 00:00:00 2001 From: GrahamTheCoder Date: Sun, 21 Apr 2024 16:40:02 +0100 Subject: [PATCH 4/9] Convert file scoped namespace declarations --- CodeConverter/VB/NodesVisitor.cs | 6 +++++- Tests/VB/NamespaceLevelTests.cs | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CodeConverter/VB/NodesVisitor.cs b/CodeConverter/VB/NodesVisitor.cs index 9c78f384b..4e3c345f4 100644 --- a/CodeConverter/VB/NodesVisitor.cs +++ b/CodeConverter/VB/NodesVisitor.cs @@ -156,7 +156,11 @@ public override VisualBasicSyntaxNode VisitAttributeArgument(CSSyntax.AttributeA } #endregion - public override VisualBasicSyntaxNode VisitNamespaceDeclaration(CSSyntax.NamespaceDeclarationSyntax node) + public override VisualBasicSyntaxNode VisitFileScopedNamespaceDeclaration(FileScopedNamespaceDeclarationSyntax node) => ConvertNamespaceDeclaration(node); + + public override VisualBasicSyntaxNode VisitNamespaceDeclaration(CSSyntax.NamespaceDeclarationSyntax node) => ConvertNamespaceDeclaration(node); + + private VisualBasicSyntaxNode ConvertNamespaceDeclaration(BaseNamespaceDeclarationSyntax node) { foreach (var @using in node.Usings) _importsToConvert.AddRange(node.Usings); diff --git a/Tests/VB/NamespaceLevelTests.cs b/Tests/VB/NamespaceLevelTests.cs index 3d1f08241..3b8c09c25 100644 --- a/Tests/VB/NamespaceLevelTests.cs +++ b/Tests/VB/NamespaceLevelTests.cs @@ -66,6 +66,21 @@ End Class End Namespace"); } + [Fact] + public async Task TestClassWithNamespaceStatementAsync() + { + await TestConversionCSharpToVisualBasicAsync(@"namespace Test.@class; + +class TestClass +{ +} +", @"Namespace Test.class + + Friend Class TestClass(Of T) + End Class +End Namespace"); + } + [Fact] public async Task TestInternalStaticClassAsync() { From 365302ec756b7e4bc28be1d664473f84d52b2308 Mon Sep 17 00:00:00 2001 From: GrahamTheCoder Date: Sun, 21 Apr 2024 16:45:27 +0100 Subject: [PATCH 5/9] Remove support for previous Visual Studio versions. 17.6+ only --- CHANGELOG.md | 2 ++ README.md | 4 ++-- Vsix/source.extension.vsixmanifest | 11 ++--------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1ad1859b..b3d9ab1c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Vsix +* Compatible with Visual Studio 2022 17.6 onwards ### VB -> C# ### C# -> VB +* Converts file scoped namespaces ## [9.2.5] - 2024-01-31 diff --git a/README.md b/README.md index f06a1a492..06dd1980c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Convert code from VB.NET to C# (and vice versa) using Roslyn - all free and open * [Visual Studio extension](https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.CodeConverter) * To install close VS and double-click the downloadeded .vsix file * [Online snippet converter](https://icsharpcode.github.io/CodeConverter/) -* Command line `dotnet tool install ICSharpCode.CodeConverter.codeconv --global` (still requires VS2019+ installed) +* Command line `dotnet tool install ICSharpCode.CodeConverter.codeconv --global` (still requires VS2022 17.6+ installed) * [Nuget library](https://www.nuget.org/packages/ICSharpCode.CodeConverter/) (this underpins all other free converters you'll find online) See [wiki](https://github.com/icsharpcode/CodeConverter/wiki) for advice on getting the best results, or the [changelog](https://github.com/icsharpcode/CodeConverter/blob/master/CHANGELOG.md) for recent improvements. @@ -15,7 +15,7 @@ See [wiki](https://github.com/icsharpcode/CodeConverter/wiki) for advice on gett Adds context menu items to convert projects/files between VB.NET and C#. See the [wiki documentation](https://github.com/icsharpcode/CodeConverter/wiki) for advice / help using it. -Download from [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.CodeConverter) (Use VS 2019+) +Download from [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.CodeConverter) (Use VS 2022 17.6+) * Flexible: Convert a small selection, or a whole solution in one go, in either direction. * Accurate: Full project context (through Roslyn) is used to get the most accurate conversion. diff --git a/Vsix/source.extension.vsixmanifest b/Vsix/source.extension.vsixmanifest index 34331cf18..7fedb2238 100644 --- a/Vsix/source.extension.vsixmanifest +++ b/Vsix/source.extension.vsixmanifest @@ -13,20 +13,13 @@ code converter vb csharp visual basic csharp net translate - - x86 - - + amd64 - + arm64 - - - - From 6ed1211e65a707c6b50103fdb7309744bd76ccba Mon Sep 17 00:00:00 2001 From: GrahamTheCoder Date: Sun, 21 Apr 2024 17:08:49 +0100 Subject: [PATCH 6/9] Update types needed in 4.8.0 --- CodeConverter/CSharp/CommonConversions.cs | 2 +- CodeConverter/CSharp/HandledEventsAnalysis.cs | 2 +- CodeConverter/CSharp/LambdaConverter.cs | 2 +- .../CSharp/MethodBodyExecutableStatementVisitor.cs | 2 +- CodeConverter/CSharp/TypeConversionAnalyzer.cs | 6 +++--- CodeConverter/VB/NodesVisitor.cs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CodeConverter/CSharp/CommonConversions.cs b/CodeConverter/CSharp/CommonConversions.cs index aa05a3a0c..2d57fc120 100644 --- a/CodeConverter/CSharp/CommonConversions.cs +++ b/CodeConverter/CSharp/CommonConversions.cs @@ -674,7 +674,7 @@ public static ExpressionSyntax ThrowawayParameters(ExpressionSyntax invocable, i return SyntaxFactory.ParenthesizedLambdaExpression(parameters, SyntaxFactory.InvocationExpression(invocable)); } - public static CSSyntax.ParameterListSyntax CreateParameterList(IEnumerable ps) + public static CSSyntax.ParameterListSyntax CreateParameterList(IEnumerable ps) { return SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(ps)); } diff --git a/CodeConverter/CSharp/HandledEventsAnalysis.cs b/CodeConverter/CSharp/HandledEventsAnalysis.cs index 854176c93..8493d74da 100644 --- a/CodeConverter/CSharp/HandledEventsAnalysis.cs +++ b/CodeConverter/CSharp/HandledEventsAnalysis.cs @@ -85,7 +85,7 @@ private PropertyDeclarationSyntax GetDeclarationsForHandlingBaseMembers((EventCo var prop = (PropertyDeclarationSyntax) _commonConversions.CsSyntaxGenerator.Declaration(basePropertyEventSubscription.PropertyDetails.Property); var modifiers = prop.Modifiers.RemoveWhere(m => m.IsKind(SyntaxKind.VirtualKeyword)).Add(SyntaxFactory.Token(SyntaxKind.OverrideKeyword)); //TODO Stash away methodwithandles in constructor that don't match any symbol from that type, to match here against base symbols - return GetDeclarationsForFieldBackedProperty(basePropertyEventSubscription.HandledMethods, SyntaxFactory.List(), modifiers, + return GetDeclarationsForFieldBackedProperty(basePropertyEventSubscription.HandledMethods, SyntaxFactory.List(), modifiers, prop.Type, prop.Identifier, SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.BaseExpression(), ValidSyntaxFactory.IdentifierName(prop.Identifier))); } diff --git a/CodeConverter/CSharp/LambdaConverter.cs b/CodeConverter/CSharp/LambdaConverter.cs index 6fee48063..ad81097c1 100644 --- a/CodeConverter/CSharp/LambdaConverter.cs +++ b/CodeConverter/CSharp/LambdaConverter.cs @@ -67,7 +67,7 @@ private async Task ConvertToFunctionDeclarationOrNullAsync(VBS // Could do: See if we can improve upon returning "object" for pretty much everything (which is what the symbols say) // I believe that in general, special VB functions such as MultiplyObject are designed to work the same as integer when given two integers for example. // If all callers currently pass an integer, perhaps it'd be more idiomatic in C# to specify "int", than to have Operators - var paramsWithTypes = anonFuncOp.Symbol.Parameters.Select(p => CommonConversions.CsSyntaxGenerator.ParameterDeclaration(p)); + var paramsWithTypes = anonFuncOp.Symbol.Parameters.Select(p => (ParameterSyntax) CommonConversions.CsSyntaxGenerator.ParameterDeclaration(p)); var paramListWithTypes = param.WithParameters(SyntaxFactory.SeparatedList(paramsWithTypes)); if (potentialAncestorDeclarationOperation is IFieldInitializerOperation fieldInit) { diff --git a/CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs b/CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs index 79adfdc80..a88510c74 100644 --- a/CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs +++ b/CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs @@ -611,7 +611,7 @@ public override async Task> VisitForBlock(VBSyntax.F } - var preLoopStatements = new List(); + var preLoopStatements = new List(); var csToValue = await stmt.ToValue.AcceptAsync(_expressionVisitor); csToValue = CommonConversions.TypeConversionAnalyzer.AddExplicitConversion(stmt.ToValue, csToValue?.SkipIntoParens(), forceTargetType: controlVarType); diff --git a/CodeConverter/CSharp/TypeConversionAnalyzer.cs b/CodeConverter/CSharp/TypeConversionAnalyzer.cs index 38c360b09..a354e2748 100644 --- a/CodeConverter/CSharp/TypeConversionAnalyzer.cs +++ b/CodeConverter/CSharp/TypeConversionAnalyzer.cs @@ -242,17 +242,17 @@ private CSSyntax.NameSyntax GetCommonDelegateTypeOrNull(VBSyntax.ExpressionSynta private CSSyntax.NameSyntax CreateCommonDelegateTypeSyntax(IMethodSymbol vbLambda) { var parameters = vbLambda.Parameters - .Select(p => _csSyntaxGenerator.TypeExpression(p.Type)); + .Select(p => (TypeSyntax) _csSyntaxGenerator.TypeExpression(p.Type)); if (vbLambda.ReturnType.IsSystemVoid()) { return CreateType("Action", parameters); } - var typeExpression = _csSyntaxGenerator.TypeExpression(vbLambda.ReturnType); + var typeExpression = (TypeSyntax) _csSyntaxGenerator.TypeExpression(vbLambda.ReturnType); return CreateType("Func", parameters.Concat(typeExpression)); } - private static CSSyntax.NameSyntax CreateType(string baseTypeName, IEnumerable parameters) + private static CSSyntax.NameSyntax CreateType(string baseTypeName, IEnumerable parameters) { var parameterList = SyntaxFactory.TypeArgumentList(SyntaxFactory.SeparatedList(parameters)); if (!parameterList.Arguments.Any()) return ValidSyntaxFactory.IdentifierName(baseTypeName); diff --git a/CodeConverter/VB/NodesVisitor.cs b/CodeConverter/VB/NodesVisitor.cs index 4e3c345f4..48911590e 100644 --- a/CodeConverter/VB/NodesVisitor.cs +++ b/CodeConverter/VB/NodesVisitor.cs @@ -657,7 +657,7 @@ public override VisualBasicSyntaxNode VisitEventDeclaration(CSSyntax.EventDeclar ); } else { if ((int)LanguageVersion < 14) { - var conditionalStatement = _vbSyntaxGenerator.IfStatement( + var conditionalStatement = (StatementSyntax) _vbSyntaxGenerator.IfStatement( _vbSyntaxGenerator.ReferenceNotEqualsExpression(eventFieldIdentifier, _vbSyntaxGenerator.NullLiteralExpression()), SyntaxFactory.InvocationExpression( From 7772c1c1ada3b3377f0ab3231062da9e5e60c270 Mon Sep 17 00:00:00 2001 From: GrahamTheCoder Date: Sun, 21 Apr 2024 17:22:37 +0100 Subject: [PATCH 7/9] Revert to 4.1.0 before https://github.com/dotnet/roslyn/issues/63921 was introduced The issue says it's fixed, but the tests can't run due to the issue --- CHANGELOG.md | 2 +- CodeConverter/CSharp/CommonConversions.cs | 4 ++-- .../CSharp/ProjectMergedDeclarationExtensions.cs | 2 +- CodeConverter/CodeConverter.csproj | 5 +++-- CodeConverter/Common/SymbolRenamer.cs | 2 +- .../CodeConv.NetFramework/CodeConv.NetFramework.csproj | 10 +++++----- CommandLine/CodeConv/CodeConv.csproj | 6 +++--- Func/Func.csproj | 10 +++++----- README.md | 4 ++-- Tests/Tests.csproj | 8 ++++---- 10 files changed, 27 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3d9ab1c8..c836d1acd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Vsix -* Compatible with Visual Studio 2022 17.6 onwards +* Compatible with Visual Studio 2022 17.1 onwards ### VB -> C# diff --git a/CodeConverter/CSharp/CommonConversions.cs b/CodeConverter/CSharp/CommonConversions.cs index 2d57fc120..4402d5a05 100644 --- a/CodeConverter/CSharp/CommonConversions.cs +++ b/CodeConverter/CSharp/CommonConversions.cs @@ -569,7 +569,7 @@ public static CSSyntax.VariableDeclaratorSyntax CreateVariableDeclarator(string { if (operation is IPropertyReferenceOperation pro && pro.Arguments.Any() && !VisualBasicExtensions.IsDefault(pro.Property)) { - var isSetter = pro.Parent.Kind == OperationKind.SimpleAssignment && pro.Parent.ChildOperations.First() == pro; + var isSetter = pro.Parent.Kind == OperationKind.SimpleAssignment && pro.Parent.Children.First() == pro; var extraArg = isSetter ? await GetParameterizedSetterArgAsync(operation) : null; @@ -674,7 +674,7 @@ public static ExpressionSyntax ThrowawayParameters(ExpressionSyntax invocable, i return SyntaxFactory.ParenthesizedLambdaExpression(parameters, SyntaxFactory.InvocationExpression(invocable)); } - public static CSSyntax.ParameterListSyntax CreateParameterList(IEnumerable ps) + public static CSSyntax.ParameterListSyntax CreateParameterList(IEnumerable ps) { return SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(ps)); } diff --git a/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs b/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs index edd019226..cf41e9689 100644 --- a/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs +++ b/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs @@ -164,7 +164,7 @@ private static async Task RenamePrefixAsync(Project project, string old for (var symbolToRename = await GetElementToRename(project); symbolToRename != null; symbolToRename = await GetElementToRename(project, toSkip)) { string newName = symbolToRename.Name.Replace(oldNamePrefix, newNamePrefix); try { - var renamedSolution = await Renamer.RenameSymbolAsync(project.Solution, symbolToRename, new SymbolRenameOptions(), newName, cancellationToken); + var renamedSolution = await Renamer.RenameSymbolAsync(project.Solution, symbolToRename, newName, project.Solution.Workspace.Options, cancellationToken); project = renamedSolution.GetProject(project.Id); } catch (Exception e) { toSkip++; diff --git a/CodeConverter/CodeConverter.csproj b/CodeConverter/CodeConverter.csproj index 1c292b5d9..80642c84b 100644 --- a/CodeConverter/CodeConverter.csproj +++ b/CodeConverter/CodeConverter.csproj @@ -36,8 +36,9 @@ - - + + + all diff --git a/CodeConverter/Common/SymbolRenamer.cs b/CodeConverter/Common/SymbolRenamer.cs index 3891a30b6..5ee789494 100644 --- a/CodeConverter/Common/SymbolRenamer.cs +++ b/CodeConverter/Common/SymbolRenamer.cs @@ -35,7 +35,7 @@ public static async Task PerformRenamesAsync(Project project, IEnumerab ISymbol currentDeclaration = SymbolFinder.FindSimilarSymbols(originalSymbol, compilation).FirstOrDefault(); if (currentDeclaration == null) continue; //Must have already renamed this symbol for a different reason - solution = await Renamer.RenameSymbolAsync(solution, currentDeclaration, new SymbolRenameOptions(), newName, cancellationToken); + solution = await Renamer.RenameSymbolAsync(solution, currentDeclaration, newName, solution.Workspace.Options); } return solution.GetProject(project.Id); diff --git a/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj b/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj index c67bca35f..9f1735fa6 100644 --- a/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj +++ b/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj @@ -10,14 +10,14 @@ - + - - - + + + - + diff --git a/CommandLine/CodeConv/CodeConv.csproj b/CommandLine/CodeConv/CodeConv.csproj index db838c8c3..83443a382 100644 --- a/CommandLine/CodeConv/CodeConv.csproj +++ b/CommandLine/CodeConv/CodeConv.csproj @@ -33,9 +33,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers diff --git a/Func/Func.csproj b/Func/Func.csproj index a7605188b..1efbf0c58 100644 --- a/Func/Func.csproj +++ b/Func/Func.csproj @@ -31,11 +31,11 @@ - - - - - + + + + + diff --git a/README.md b/README.md index 06dd1980c..a7a7ae725 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Convert code from VB.NET to C# (and vice versa) using Roslyn - all free and open * [Visual Studio extension](https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.CodeConverter) * To install close VS and double-click the downloadeded .vsix file * [Online snippet converter](https://icsharpcode.github.io/CodeConverter/) -* Command line `dotnet tool install ICSharpCode.CodeConverter.codeconv --global` (still requires VS2022 17.6+ installed) +* Command line `dotnet tool install ICSharpCode.CodeConverter.codeconv --global` (still requires VS2022 17.1+ installed) * [Nuget library](https://www.nuget.org/packages/ICSharpCode.CodeConverter/) (this underpins all other free converters you'll find online) See [wiki](https://github.com/icsharpcode/CodeConverter/wiki) for advice on getting the best results, or the [changelog](https://github.com/icsharpcode/CodeConverter/blob/master/CHANGELOG.md) for recent improvements. @@ -15,7 +15,7 @@ See [wiki](https://github.com/icsharpcode/CodeConverter/wiki) for advice on gett Adds context menu items to convert projects/files between VB.NET and C#. See the [wiki documentation](https://github.com/icsharpcode/CodeConverter/wiki) for advice / help using it. -Download from [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.CodeConverter) (Use VS 2022 17.6+) +Download from [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.CodeConverter) (Use VS 2022 17.1+) * Flexible: Convert a small selection, or a whole solution in one go, in either direction. * Accurate: Full project context (through Roslyn) is used to get the most accurate conversion. diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 8901c1bf4..01aef701e 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -36,10 +36,10 @@ - - - - + + + + From 783ecc03569037385a4bca0bd6e1270534cdaf7b Mon Sep 17 00:00:00 2001 From: GrahamTheCoder Date: Sun, 21 Apr 2024 17:23:28 +0100 Subject: [PATCH 8/9] Recharacterize the buggy formatting of linq. This is fixed again in a later version of roslyn but we can't update due to another bug https://github.com/dotnet/roslyn/issues/63921 --- .../ExpressionTests/XmlExpressionTests.cs | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Tests/CSharp/ExpressionTests/XmlExpressionTests.cs b/Tests/CSharp/ExpressionTests/XmlExpressionTests.cs index d059ca7cf..aa064b419 100644 --- a/Tests/CSharp/ExpressionTests/XmlExpressionTests.cs +++ b/Tests/CSharp/ExpressionTests/XmlExpressionTests.cs @@ -116,22 +116,22 @@ private void TestMethod() { var catalog = new XDocument( new XElement(""Catalog"", - new XElement(""Book"", new XAttribute(""id"", ""bk101""), - new XElement(""Author"", ""Garghentini, Davide""), - new XElement(""Title"", ""XML Developer's Guide""), - new XElement(""Price"", ""44.95""), - new XElement(""Description"", @"" +new XElement(""Book"", new XAttribute(""id"", ""bk101""), +new XElement(""Author"", ""Garghentini, Davide""), +new XElement(""Title"", ""XML Developer's Guide""), +new XElement(""Price"", ""44.95""), +new XElement(""Description"", @"" An in-depth look at creating applications with "", new XElement(""technology"", ""XML""), @"". For "", new XElement(""audience"", ""beginners""), @"" or "", new XElement(""audience"", ""advanced""), @"" developers. "") - ), - new XElement(""Book"", new XAttribute(""id"", ""bk331""), - new XElement(""Author"", ""Spencer, Phil""), - new XElement(""Title"", ""Developing Applications with Visual Basic .NET""), - new XElement(""Price"", ""45.95""), - new XElement(""Description"", @"" +), +new XElement(""Book"", new XAttribute(""id"", ""bk331""), +new XElement(""Author"", ""Spencer, Phil""), +new XElement(""Title"", ""Developing Applications with Visual Basic .NET""), +new XElement(""Price"", ""45.95""), +new XElement(""Description"", @"" Get the expert insights, practical code samples, and best practices you need to advance your expertise with "", new XElement(""technology"", @""Visual @@ -140,21 +140,23 @@ and best practices you need based on professional, pragmatic guidance by today's top "", new XElement(""audience"", ""developers""), @"". "") - ) +) ) ); var htmlOutput = new XElement(""html"", + new XElement(""body"", from book in catalog.Elements(""Catalog"").Elements(""Book"") select new XElement(""div"", - new XElement(""h1"", book.Elements(""Title"").Value), - new XElement(""h3"", ""By "" + book.Elements(""Author"").Value), - new XElement(""h3"", ""Price = "" + book.Elements(""Price"").Value), + new XElement(""h1"", book.Elements(""Title"").Value), + new XElement(""h3"", ""By "" + book.Elements(""Author"").Value), + new XElement(""h3"", ""Price = "" + book.Elements(""Price"").Value), + new XElement(""h2"", ""Description""), TransformDescription((string)book.Elements(""Description"").ElementAtOrDefault(0)), new XElement(""hr"") - ) - ) - ); + ) + ) + ); } public string TransformDescription(string s) From 3ff9806ecf3270e1d7a08ab89edde48b5797b1ae Mon Sep 17 00:00:00 2001 From: GrahamTheCoder Date: Sun, 21 Apr 2024 18:03:55 +0100 Subject: [PATCH 9/9] Update languageservices too (non-sdk project not seen by update) --- Vsix/Vsix.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vsix/Vsix.csproj b/Vsix/Vsix.csproj index 8e74018bf..bad7ddc59 100644 --- a/Vsix/Vsix.csproj +++ b/Vsix/Vsix.csproj @@ -51,7 +51,7 @@ - + compile; build; native; contentfiles; analyzers; buildtransitive