diff --git a/CodeConverter.sln b/CodeConverter.sln index 2ce657f52..28ea69815 100644 --- a/CodeConverter.sln +++ b/CodeConverter.sln @@ -1,16 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29721.120 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.31911.260 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeConverter", "CodeConverter\CodeConverter.csproj", "{7EA075C6-6406-445C-AB77-6C47AFF88D58}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{21DBA1CE-AF55-4159-B04B-B8C621BE8921}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vsix", "Vsix\Vsix.csproj", "{99498EF8-C9E0-433B-8D7B-EA8E9E66F0C7}" - ProjectSection(ProjectDependencies) = postProject - {CF18CBCF-67FF-46CA-8D1D-3221B7706D7D} = {CF18CBCF-67FF-46CA-8D1D-3221B7706D7D} - EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{40A4828C-D6D2-43C5-A452-36CB06649680}" ProjectSection(SolutionItems) = preProject diff --git a/CodeConverter/CSharp/CommentConvertingVisitorWrapper.cs b/CodeConverter/CSharp/CommentConvertingVisitorWrapper.cs index 2b667d457..2dc6265ee 100644 --- a/CodeConverter/CSharp/CommentConvertingVisitorWrapper.cs +++ b/CodeConverter/CSharp/CommentConvertingVisitorWrapper.cs @@ -1,28 +1,26 @@ -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Text; -using Microsoft.CodeAnalysis.VisualBasic; +using Microsoft.CodeAnalysis.Text; namespace ICSharpCode.CodeConverter.CSharp; [System.Diagnostics.DebuggerStepThrough] internal class CommentConvertingVisitorWrapper { - private readonly VBasic.VisualBasicSyntaxVisitor> _wrappedVisitor; + private readonly VBasic.VisualBasicSyntaxVisitor> _wrappedVisitor; private readonly SyntaxTree _syntaxTree; private static readonly CSSyntax.LiteralExpressionSyntax _dummyLiteral = ValidSyntaxFactory.DefaultExpression; private static readonly CSSyntax.StatementSyntax _dummyStatement = CS.SyntaxFactory.EmptyStatement(); private static readonly CSSyntax.CompilationUnitSyntax _dummyCompilationUnit = CS.SyntaxFactory.CompilationUnit(); - public CommentConvertingVisitorWrapper(VisualBasicSyntaxVisitor> wrappedVisitor, SyntaxTree syntaxTree) + public CommentConvertingVisitorWrapper(VBasic.VisualBasicSyntaxVisitor> wrappedVisitor, SyntaxTree syntaxTree) { _wrappedVisitor = wrappedVisitor; _syntaxTree = syntaxTree; } - public async Task AcceptAsync(VisualBasicSyntaxNode vbNode, SourceTriviaMapKind sourceTriviaMap) where T : CS.CSharpSyntaxNode => + public async Task AcceptAsync(VisualBasicSyntaxNode vbNode, SourceTriviaMapKind sourceTriviaMap) where T : CSharpSyntaxNode => await ConvertHandledAsync(vbNode, sourceTriviaMap); - public async Task> AcceptAsync(SeparatedSyntaxList vbNodes, SourceTriviaMapKind sourceTriviaMap) where TIn : VBasic.VisualBasicSyntaxNode where TOut : CS.CSharpSyntaxNode + public async Task> AcceptAsync(SeparatedSyntaxList vbNodes, SourceTriviaMapKind sourceTriviaMap) where TIn : VisualBasicSyntaxNode where TOut : CSharpSyntaxNode { var convertedNodes = await vbNodes.SelectAsync(n => ConvertHandledAsync(n, sourceTriviaMap)); var convertedSeparators = vbNodes.GetSeparators().Select(s => @@ -33,7 +31,7 @@ public async Task> AcceptAsync(SeparatedSyn return CS.SyntaxFactory.SeparatedList(convertedNodes, convertedSeparators); } - private async Task ConvertHandledAsync(VisualBasicSyntaxNode vbNode, SourceTriviaMapKind sourceTriviaMap) where T : CS.CSharpSyntaxNode + private async Task ConvertHandledAsync(VisualBasicSyntaxNode vbNode, SourceTriviaMapKind sourceTriviaMap) where T : CSharpSyntaxNode { try { var converted = (T)await _wrappedVisitor.Visit(vbNode); @@ -56,7 +54,7 @@ private async Task ConvertHandledAsync(VisualBasicSyntaxNode vbNode, Sourc /// /// If lots of special cases, move to wrapping the wrappedVisitor in another visitor, but I'd rather use a simple switch here initially. /// - private static T WithSourceMapping(SyntaxNode vbNode, T converted) where T : CS.CSharpSyntaxNode + private static T WithSourceMapping(SyntaxNode vbNode, T converted) where T : CSharpSyntaxNode { converted = vbNode.CopyAnnotationsTo(converted); switch (vbNode) { diff --git a/CodeConverter/CSharp/CommonConversions.cs b/CodeConverter/CSharp/CommonConversions.cs index d03543f22..b5c9c9c84 100644 --- a/CodeConverter/CSharp/CommonConversions.cs +++ b/CodeConverter/CSharp/CommonConversions.cs @@ -75,7 +75,7 @@ public CommonConversions(Document document, SemanticModel semanticModel, foreach (var name in declarator.Names) { var declaredSymbol = SemanticModel.GetDeclaredSymbol(name); - if (symbolsToSkip?.Contains(declaredSymbol) == true) continue; + if (symbolsToSkip?.Contains(declaredSymbol, SymbolEqualityComparer.IncludeNullability) == true) continue; var declaredSymbolType = declaredSymbol.GetSymbolType(); var equalsValueClauseSyntax = await ConvertEqualsValueClauseSyntaxAsync(declarator, name, vbInitValue, declaredSymbolType, declaredSymbol, initializerOrMethodDecl); var v = SyntaxFactory.VariableDeclarator(ConvertIdentifier(name.Identifier), null, equalsValueClauseSyntax); @@ -107,7 +107,7 @@ public bool ShouldPreferExplicitType(VBSyntax.ExpressionSyntax exp, exp = op.Syntax as VBSyntax.ExpressionSyntax; var vbInitConstantValue = SemanticModel.GetConstantValue(exp); isNothingLiteral = vbInitConstantValue.HasValue && vbInitConstantValue.Value == null || exp is VBSyntax.LiteralExpressionSyntax les && les.IsKind(SyntaxKind.NothingLiteralExpression); - bool shouldPreferExplicitType = expConvertedType != null && (expConvertedType.HasCsKeyword() || !expConvertedType.Equals(op.Type)); + bool shouldPreferExplicitType = expConvertedType != null && (expConvertedType.HasCsKeyword() || !expConvertedType.Equals(op.Type, SymbolEqualityComparer.IncludeNullability)); return shouldPreferExplicitType; } @@ -172,7 +172,7 @@ private CSSyntax.VariableDeclarationSyntax CreateVariableDeclaration(VariableDec CSSyntax.EqualsValueClauseSyntax equalsValueClauseSyntax, IMethodSymbol initSymbol, CSSyntax.VariableDeclaratorSyntax v) { var requireExplicitType = requireExplicitTypeForAll || - vbInitializerType != null && !Equals(declaredSymbolType, vbInitializerType); + vbInitializerType != null && !SymbolEqualityComparer.IncludeNullability.Equals(declaredSymbolType, vbInitializerType); bool useVar = equalsValueClauseSyntax != null && !preferExplicitType && !requireExplicitType; var typeSyntax = initSymbol == null || !initSymbol.IsAnonymousFunction() ? GetTypeSyntax(declaredSymbolType, useVar) @@ -267,7 +267,7 @@ public SyntaxToken ConvertIdentifier(SyntaxToken id, bool isAttribute = false, S text = idSymbol.ContainingType.Name; if (normalizedText.EndsWith("Attribute", StringComparison.OrdinalIgnoreCase)) text = text.Remove(text.Length - "Attribute".Length); - } else if (idSymbol.IsKind(SymbolKind.Parameter) && idSymbol.ContainingSymbol.IsAccessorWithValueInCsharp() && ((idSymbol.IsImplicitlyDeclared && idSymbol.Name.WithHalfWidthLatinCharacters().Equals("value", StringComparison.OrdinalIgnoreCase)) || idSymbol.Equals(idSymbol.ContainingSymbol.GetParameters().FirstOrDefault(x => !x.IsImplicitlyDeclared)))) { + } else if (idSymbol.IsKind(SymbolKind.Parameter) && idSymbol.ContainingSymbol.IsAccessorWithValueInCsharp() && ((idSymbol.IsImplicitlyDeclared && idSymbol.Name.WithHalfWidthLatinCharacters().Equals("value", StringComparison.OrdinalIgnoreCase)) || idSymbol.Equals(idSymbol.ContainingSymbol.GetParameters().FirstOrDefault(x => !x.IsImplicitlyDeclared), SymbolEqualityComparer.IncludeNullability))) { // The case above is basically that if the symbol is a parameter, and the corresponding definition is a property set definition // AND the first explicitly declared parameter is this symbol, we need to replace it with value. text = "value"; diff --git a/CodeConverter/CSharp/DefiniteAssignmentAnalyzer.cs b/CodeConverter/CSharp/DefiniteAssignmentAnalyzer.cs index b45dee7a3..931a68ac4 100644 --- a/CodeConverter/CSharp/DefiniteAssignmentAnalyzer.cs +++ b/CodeConverter/CSharp/DefiniteAssignmentAnalyzer.cs @@ -7,6 +7,6 @@ public static bool IsDefinitelyAssignedBeforeRead(ISymbol localSymbol, DataFlowA { if (!methodFlow.ReadInside.Contains(localSymbol)) return true; var unassignedVariables = methodFlow.GetVbUnassignedVariables(); - return unassignedVariables != null && !unassignedVariables.Contains(localSymbol); + return unassignedVariables != null && !unassignedVariables.Contains(localSymbol, SymbolEqualityComparer.IncludeNullability); } } \ No newline at end of file diff --git a/CodeConverter/CSharp/ExpressionNodeVisitor.cs b/CodeConverter/CSharp/ExpressionNodeVisitor.cs index 0cbd2ef49..c3ae5831b 100644 --- a/CodeConverter/CSharp/ExpressionNodeVisitor.cs +++ b/CodeConverter/CSharp/ExpressionNodeVisitor.cs @@ -1,6 +1,7 @@ using System.Collections.Immutable; using System.Data; using System.Globalization; +using System.Linq; using ICSharpCode.CodeConverter.CSharp.Replacements; using ICSharpCode.CodeConverter.Util.FromRoslyn; using Microsoft.CodeAnalysis.CSharp; @@ -70,9 +71,13 @@ private static Dictionary CreateConvertMethodsLookupByRetur var convertMethods = convertType.GetMembers().Where(m => m.Name.StartsWith("To", StringComparison.Ordinal) && m.GetParameters().Length == 1); + +#pragma warning disable RS1024 // Compare symbols correctly - GroupBy and ToDictionary use the same logic to dedupe as to lookup, so it doesn't matter which equality is used var methodsByType = convertMethods .GroupBy(m => new { ReturnType = m.GetReturnType(), Name = $"{ConvertType.FullName}.{m.Name}" }) .ToDictionary(m => m.Key.ReturnType, m => m.Key.Name); +#pragma warning restore RS1024 // Compare symbols correctly + return methodsByType; } @@ -519,7 +524,7 @@ private ExpressionSyntax HoistByRefDeclaration(VBSyntax.SimpleArgumentSyntax nod { string prefix = $"arg{argName}"; var expressionTypeInfo = _semanticModel.GetTypeInfo(node.Expression); - bool useVar = expressionTypeInfo.Type?.Equals(expressionTypeInfo.ConvertedType) == true && !CommonConversions.ShouldPreferExplicitType(node.Expression, expressionTypeInfo.ConvertedType, out var _); + bool useVar = expressionTypeInfo.Type?.Equals(expressionTypeInfo.ConvertedType, SymbolEqualityComparer.IncludeNullability) == true && !CommonConversions.ShouldPreferExplicitType(node.Expression, expressionTypeInfo.ConvertedType, out var _); var typeSyntax = CommonConversions.GetTypeSyntax(expressionTypeInfo.ConvertedType, useVar); if (refLValue is ElementAccessExpressionSyntax eae) { @@ -866,7 +871,7 @@ public override async Task VisitBinaryExpression(VBasic.Syntax } omitConversion |= lhsTypeInfo.Type != null && rhsTypeInfo.Type != null && - lhsTypeInfo.Type.IsEnumType() && Equals(lhsTypeInfo.Type, rhsTypeInfo.Type) + lhsTypeInfo.Type.IsEnumType() && SymbolEqualityComparer.IncludeNullability.Equals(lhsTypeInfo.Type, rhsTypeInfo.Type) && !node.IsKind(VBasic.SyntaxKind.AddExpression, VBasic.SyntaxKind.SubtractExpression, VBasic.SyntaxKind.MultiplyExpression, VBasic.SyntaxKind.DivideExpression, VBasic.SyntaxKind.IntegerDivideExpression, VBasic.SyntaxKind.ModuloExpression) && forceLhsTargetType == null && forceRhsTargetType == null; lhs = omitConversion ? lhs : CommonConversions.TypeConversionAnalyzer.AddExplicitConversion(node.Left, lhs, forceTargetType: forceLhsTargetType); @@ -1029,7 +1034,7 @@ private static bool IsElementAtOrDefaultInvocation(ISymbol invocationSymbol, ISy { return (expressionSymbol != null && (invocationSymbol?.Name == nameof(Enumerable.ElementAtOrDefault) - && !expressionSymbol.Equals(invocationSymbol))); + && !expressionSymbol.Equals(invocationSymbol, SymbolEqualityComparer.IncludeNullability))); } private ExpressionSyntax GetElementAtOrDefaultExpression(ISymbol expressionType, @@ -1668,7 +1673,7 @@ RefConversion GetRefConversion(VBSyntax.ExpressionSyntax expression) IsRefArrayAcces(expression)) { var typeInfo = _semanticModel.GetTypeInfo(expression); - bool isTypeMismatch = typeInfo.Type == null || !typeInfo.Type.Equals(typeInfo.ConvertedType); + bool isTypeMismatch = typeInfo.Type == null || !typeInfo.Type.Equals(typeInfo.ConvertedType, SymbolEqualityComparer.IncludeNullability); if (isTypeMismatch) { return RefConversion.PreAndPostAssignment; diff --git a/CodeConverter/CSharp/HandledEventsAnalysis.cs b/CodeConverter/CSharp/HandledEventsAnalysis.cs index 0b56907a1..88cf7c154 100644 --- a/CodeConverter/CSharp/HandledEventsAnalysis.cs +++ b/CodeConverter/CSharp/HandledEventsAnalysis.cs @@ -68,7 +68,7 @@ public IEnumerable CreateDelegatingMethodsRequiredByIni public IEnumerable GetDeclarationsForHandlingBaseMembers() { return _handlingMethodsByPropertyName.Values - .Where(m => m.EventContainer.Kind == EventContainerKind.Property && !_type.Equals(m.PropertyDetails.Property?.ContainingType)) + .Where(m => m.EventContainer.Kind == EventContainerKind.Property && !_type.Equals(m.PropertyDetails.Property?.ContainingType, SymbolEqualityComparer.IncludeNullability)) .Select(x => GetDeclarationsForHandlingBaseMembers(x)); } diff --git a/CodeConverter/CSharp/HandledEventsAnalyzer.cs b/CodeConverter/CSharp/HandledEventsAnalyzer.cs index 3f7489198..3858475eb 100644 --- a/CodeConverter/CSharp/HandledEventsAnalyzer.cs +++ b/CodeConverter/CSharp/HandledEventsAnalyzer.cs @@ -30,9 +30,11 @@ public static Task AnalyzeAsync(CommonConversions commonC private async Task AnalyzeAsync() { +#pragma warning disable RS1024 // Compare symbols correctly - bug in analyzer https://github.com/dotnet/roslyn-analyzers/issues/3427#issuecomment-929104517 var ancestorPropsMembersByName = _type.GetBaseTypesAndThis().SelectMany(t => t.GetMembers().Where(m => m.IsKind(SymbolKind.Property))) .GroupBy(m => m.Name, StringComparer.OrdinalIgnoreCase) .ToDictionary(m => m.Key, g => g.First(), StringComparer.OrdinalIgnoreCase); // Uses the fact that GroupBy maintains addition order to get the closest declaration +#pragma warning restore RS1024 // Compare symbols correctly var writtenWithEventsProperties = await ancestorPropsMembersByName.Values.OfType().ToAsyncEnumerable().ToDictionaryAwaitAsync(async p => p.Name, async p => (p, await IsNeverWrittenOrOverriddenAsync(p)), StringComparer.OrdinalIgnoreCase); @@ -40,7 +42,7 @@ private async Task AnalyzeAsync() .SelectMany(HandledEvents) .ToLookup(eventAndMethod => eventAndMethod.EventContainer); var eventsThatMayNeedInheritors = writtenWithEventsProperties - .Where(p => !p.Value.Item2 && p.Value.p.ContainingType.Equals(_type)) + .Where(p => !p.Value.Item2 && p.Value.p.ContainingType.Equals(_type, SymbolEqualityComparer.IncludeNullability)) .Select(p => (EventContainer: new HandledEventsAnalysis.EventContainer(HandledEventsAnalysis.EventContainerKind.Property, p.Key), PropertyDetails: p.Value, Array.Empty<(EventDescriptor Event, IMethodSymbol HandlingMethod, int ParametersToDiscard)>())) .Where(e => !eventContainerToMethods.Contains(e.EventContainer)); diff --git a/CodeConverter/CSharp/LocalVariableAnalyzer.cs b/CodeConverter/CSharp/LocalVariableAnalyzer.cs index 4eddeb567..9e89edcca 100644 --- a/CodeConverter/CSharp/LocalVariableAnalyzer.cs +++ b/CodeConverter/CSharp/LocalVariableAnalyzer.cs @@ -9,7 +9,9 @@ internal static class LocalVariableAnalyzer public static async Task> GetDescendantsToInlineInLoopAsync(this Solution solution, SemanticModel semanticModel, VisualBasicSyntaxNode methodNode) { var forEachControlVariables = await methodNode.DescendantNodes().OfType().SelectAsync(forEach => GetLoopVariablesToInlineAsync(solution, semanticModel, forEach)); - return new HashSet(forEachControlVariables.Where(f => f != null), SymbolEquivalenceComparer.Instance); +#pragma warning disable RS1024 // Compare symbols correctly - analyzer bug, this is the comparer the docs recommend + return new HashSet(forEachControlVariables.Where(f => f != null), SymbolEqualityComparer.IncludeNullability); +#pragma warning restore RS1024 // Compare symbols correctly } private static async Task GetLoopVariablesToInlineAsync(Solution solution, SemanticModel semanticModel, ForEachBlockSyntax block) diff --git a/CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs b/CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs index f35023d4c..8205c0724 100644 --- a/CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs +++ b/CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs @@ -662,7 +662,7 @@ public override async Task> VisitForEachBlock(VBSynt var explicitCastWouldHaveNoEffect = variableType?.SpecialType == SpecialType.System_Object || _semanticModel.GetTypeInfo(stmt.Expression).ConvertedType.IsEnumerableOfExactType(variableType); type = CommonConversions.GetTypeSyntax(varSymbol.GetSymbolType(), explicitCastWouldHaveNoEffect); var v = await stmt.ControlVariable.AcceptAsync(_expressionVisitor); - if (_localsToInlineInLoop.Contains(varSymbol) && v is IdentifierNameSyntax vId) { + if (_localsToInlineInLoop.Contains(varSymbol, SymbolEqualityComparer.IncludeNullability) && v is IdentifierNameSyntax vId) { id = vId.Identifier; } else { id = CommonConversions.CsEscapedIdentifier(GetUniqueVariableNameInScope(node, "current" + varSymbol.Name.ToPascalCase())); diff --git a/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs b/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs index ce2de37fd..cf41e9689 100644 --- a/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs +++ b/CodeConverter/CSharp/ProjectMergedDeclarationExtensions.cs @@ -63,7 +63,7 @@ public static async Task WithRenamedMergedMyNamespaceAsync(this Project var projectDir = Path.Combine(vbProject.GetDirectoryPath(), "My Project"); var compilation = await vbProject.GetCompilationAsync(cancellationToken); - var embeddedSourceTexts = await GetAllEmbeddedSourceText(compilation).Select((r, i) => (Text: r, Suffix: $".Static.{i+1}")).ToArrayAsync(cancellationToken); + var embeddedSourceTexts = await GetAllEmbeddedSourceTextAsync(compilation).Select((r, i) => (Text: r, Suffix: $".Static.{i+1}")).ToArrayAsync(cancellationToken); var generatedSourceTexts = (Text: await GetDynamicallyGeneratedSourceTextAsync(compilation), Suffix: ".Dynamic").Yield(); foreach (var (text, suffix) in embeddedSourceTexts.Concat(generatedSourceTexts)) { @@ -79,7 +79,7 @@ private static Project WithRenamespacedDocument(string baseName, Project vbProje return vbProject.AddDocument(baseName, sourceText.ReNamespace(), filePath: Path.Combine(myProjectDirPath, baseName + ".Designer.vb")).Project; } - private static async IAsyncEnumerable GetAllEmbeddedSourceText(Compilation compilation) + private static async IAsyncEnumerable GetAllEmbeddedSourceTextAsync(Compilation compilation) { var roots = await compilation.SourceModule.GlobalNamespace.Locations. Where(l => !l.IsInSource).Select(CachedReflectedDelegates.GetEmbeddedSyntaxTree) diff --git a/CodeConverter/CSharp/TypeConversionAnalyzer.cs b/CodeConverter/CSharp/TypeConversionAnalyzer.cs index 6e58c69a1..752219645 100644 --- a/CodeConverter/CSharp/TypeConversionAnalyzer.cs +++ b/CodeConverter/CSharp/TypeConversionAnalyzer.cs @@ -137,8 +137,8 @@ public TypeConversionKind AnalyzeConversion(VBSyntax.ExpressionSyntax vbNode, bo return TypeConversionKind.NonDestructiveCast; } - if (vbType.Equals(vbConvertedType) || - (vbConvertedType.IsNullable() && vbType.Equals(vbConvertedType.GetNullableUnderlyingType())) || + if (vbType.Equals(vbConvertedType, SymbolEqualityComparer.IncludeNullability) || + (vbConvertedType.IsNullable() && vbType.Equals(vbConvertedType.GetNullableUnderlyingType(), SymbolEqualityComparer.IncludeNullability)) || vbConvertedType.SpecialType == SpecialType.System_Object) { return TypeConversionKind.Identity; } @@ -323,7 +323,7 @@ private bool IsExplicitNumericConversion(VBSyntax.ExpressionSyntax vbNode) private static TypeConversionKind AnalyzeVbConversion(bool alwaysExplicit, ITypeSymbol vbType, ITypeSymbol vbConvertedType, Conversion vbConversion) { - if (vbType.Equals(vbConvertedType) || vbConversion.IsIdentity) { + if (vbType.Equals(vbConvertedType, SymbolEqualityComparer.IncludeNullability) || vbConversion.IsIdentity) { return TypeConversionKind.Identity; } diff --git a/CodeConverter/CSharp/VBToCSProjectContentsConverter.cs b/CodeConverter/CSharp/VBToCSProjectContentsConverter.cs index 58dfef1ac..595f5ecd0 100644 --- a/CodeConverter/CSharp/VBToCSProjectContentsConverter.cs +++ b/CodeConverter/CSharp/VBToCSProjectContentsConverter.cs @@ -49,9 +49,11 @@ public async Task InitializeSourceAsync(Project project) SourceProject = await WithProjectLevelWinformsAdjustmentsAsync(project); var compilation = await project.GetCompilationAsync(_cancellationToken); +#pragma warning disable RS1024 // Compare symbols correctly - analzyer bug, I'm intentionally using my own comparer, not the default ambiguous one. The default comparer wouldn't manage with cross-compilation comparison in all cases _typeToInheritors = compilation.GetAllNamespacesAndTypes().OfType() .Where(t => t.BaseType?.IsDefinedInSource() == true) .ToLookup(t => t.BaseType, TypeSymbolFullNameComparer.Instance); +#pragma warning restore RS1024 // Compare symbols correctly } private class TypeSymbolFullNameComparer : IEqualityComparer @@ -95,7 +97,7 @@ private static string GetPathRelativeToProject(string projDirPath, string p) return p.Replace(projDirPath, "").TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); } - public async IAsyncEnumerable GetAdditionalConversionResults(IReadOnlyCollection additionalDocumentsToConvert, [EnumeratorCancellation] CancellationToken cancellationToken) + public async IAsyncEnumerable GetAdditionalConversionResultsAsync(IReadOnlyCollection additionalDocumentsToConvert, [EnumeratorCancellation] CancellationToken cancellationToken) { string projDirPath = SourceProject.GetDirectoryPath(); foreach (var doc in additionalDocumentsToConvert) { diff --git a/CodeConverter/CodeConverter.csproj b/CodeConverter/CodeConverter.csproj index 13f6f73b7..ae59dd4d7 100644 --- a/CodeConverter/CodeConverter.csproj +++ b/CodeConverter/CodeConverter.csproj @@ -31,21 +31,21 @@ - - + + all runtime; build; native; contentfiles; analyzers - - + + - + all diff --git a/CodeConverter/Common/AsyncEnumerableTaskExtensions.cs b/CodeConverter/Common/AsyncEnumerableTaskExtensions.cs index 172323578..58d3a367f 100644 --- a/CodeConverter/Common/AsyncEnumerableTaskExtensions.cs +++ b/CodeConverter/Common/AsyncEnumerableTaskExtensions.cs @@ -18,7 +18,7 @@ public static async Task SelectManyAsync(this IEnumera /// /// Inspired by https://stackoverflow.com/a/58564740/1128762 /// - public static async IAsyncEnumerable ParallelSelectAwait(this IEnumerable source, + public static async IAsyncEnumerable ParallelSelectAwaitAsync(this IEnumerable source, Func> selector, int maxDop, [EnumeratorCancellation] CancellationToken token = default) { var processor = new TransformBlock(selector, new ExecutionDataflowBlockOptions { diff --git a/CodeConverter/Common/DocumentExtensions.cs b/CodeConverter/Common/DocumentExtensions.cs index 6a8f70302..e853c4fd2 100644 --- a/CodeConverter/Common/DocumentExtensions.cs +++ b/CodeConverter/Common/DocumentExtensions.cs @@ -113,8 +113,9 @@ private static SyntaxNode WithWarningAnnotation(SyntaxNode node, string warningT { return node.WithAdditionalAnnotations(new SyntaxAnnotation(AnnotationConstants.ConversionErrorAnnotationKind, warningText)); } - private static OptionSet GetVBOptions(DocumentOptionSet options) { - return options.WithChangedOption(SimplificationOptions.PreferImplicitTypeInLocalDeclaration, false); + private static OptionSet GetVBOptions(DocumentOptionSet options) + { + return options; } private static OptionSet GetCSOptions(DocumentOptionSet options) { return options; diff --git a/CodeConverter/Common/EnumerableExtensions.cs b/CodeConverter/Common/EnumerableExtensions.cs index fb02abb6b..f8597897d 100644 --- a/CodeConverter/Common/EnumerableExtensions.cs +++ b/CodeConverter/Common/EnumerableExtensions.cs @@ -1,4 +1,5 @@ using System.Collections.ObjectModel; +using Microsoft.VisualStudio.Threading; namespace ICSharpCode.CodeConverter.Common; @@ -90,7 +91,13 @@ public static IEnumerable Yield(this T singleElement) yield return singleElement; } - public static async Task> YieldAsync(this Task task) => (await task).Yield(); + public static async Task> YieldAsync(this Task task) + { + await TaskScheduler.Default; +#pragma warning disable VSTHRD003 // Avoid awaiting foreign Tasks - We've just switched away from the main thread so can't deadlock + return (await task).Yield(); +#pragma warning restore VSTHRD003 // Avoid awaiting foreign Tasks + } public static IEnumerable YieldNotNull(this T singleElement) { diff --git a/CodeConverter/Common/IProjectContentsConverter.cs b/CodeConverter/Common/IProjectContentsConverter.cs index 638f298e3..d17569cb6 100644 --- a/CodeConverter/Common/IProjectContentsConverter.cs +++ b/CodeConverter/Common/IProjectContentsConverter.cs @@ -9,5 +9,5 @@ public interface IProjectContentsConverter OptionalOperations OptionalOperations { get; } Task SingleFirstPassAsync(Document document); Task<(Project project, List> firstPassDocIds)> GetConvertedProjectAsync(WipFileConversion[] firstPassResults); - public IAsyncEnumerable GetAdditionalConversionResults(IReadOnlyCollection additionalDocumentsToConvert, CancellationToken cancellationToken); + public IAsyncEnumerable GetAdditionalConversionResultsAsync(IReadOnlyCollection additionalDocumentsToConvert, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/CodeConverter/Common/LanguageConversionExtensions.cs b/CodeConverter/Common/LanguageConversionExtensions.cs index 2f1aa2af8..178037b24 100644 --- a/CodeConverter/Common/LanguageConversionExtensions.cs +++ b/CodeConverter/Common/LanguageConversionExtensions.cs @@ -1,4 +1,5 @@ -using Microsoft.CodeAnalysis.Text; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Text; namespace ICSharpCode.CodeConverter.Common; @@ -7,7 +8,11 @@ public static SyntaxTree MakeFullCompilationUnit(this ILanguageConversion langua var tree= languageConversion.CreateTree(code); var root = tree.GetRoot(); textSpan = null; - var rootChildren = root.ChildNodes().ToList(); + + var rootChildren = root.ChildNodes() + //https://github.com/icsharpcode/CodeConverter/issues/825 + .Select(c => c is GlobalStatementSyntax {Statement: var s} ? s : c) + .ToList(); var requiresSurroundingClass = rootChildren.Any(languageConversion.MustBeContainedByClass); var requiresSurroundingMethod = rootChildren.All(languageConversion.CanBeContainedByMethod); diff --git a/CodeConverter/Common/ProjectConversion.cs b/CodeConverter/Common/ProjectConversion.cs index 5ad462e89..7e604b6dc 100644 --- a/CodeConverter/Common/ProjectConversion.cs +++ b/CodeConverter/Common/ProjectConversion.cs @@ -71,10 +71,10 @@ public static async IAsyncEnumerable ConvertDocumentsAsync projectContentsConverter.SourceProject.GetDocument(doc.Id)).ToList(); var conversion = new ProjectConversion(projectContentsConverter, documents, Enumerable.Empty(), languageConversion, cancellationToken); - await foreach (var result in conversion.Convert(progress).WithCancellation(cancellationToken)) yield return result; + await foreach (var result in conversion.ConvertAsync(progress).WithCancellation(cancellationToken)) yield return result; } - public static async IAsyncEnumerable ConvertProject(Project project, + public static async IAsyncEnumerable ConvertProjectAsync(Project project, ILanguageConversion languageConversion, TextReplacementConverter textReplacementConverter, IProgress progress, [EnumeratorCancellation] CancellationToken cancellationToken, @@ -83,16 +83,16 @@ public static async IAsyncEnumerable ConvertProject(Project pr using var roslynEntryPoint = await RoslynEntryPointAsync(progress ??= new Progress()); var projectContentsConverter = await languageConversion.CreateProjectContentsConverterAsync(project, progress, cancellationToken); var sourceFilePaths = project.Documents.Concat(projectContentsConverter.SourceProject.AdditionalDocuments).Select(d => d.FilePath).ToImmutableHashSet(); - var convertProjectContents = ConvertProjectContents(projectContentsConverter, languageConversion, progress, cancellationToken); + var convertProjectContents = ConvertProjectContentsAsync(projectContentsConverter, languageConversion, progress, cancellationToken); - var results = WithProjectFile(projectContentsConverter, textReplacementConverter, languageConversion, sourceFilePaths, convertProjectContents, replacements); + var results = WithProjectFileAsync(projectContentsConverter, textReplacementConverter, languageConversion, sourceFilePaths, convertProjectContents, replacements); await foreach (var result in results.WithCancellation(cancellationToken)) yield return result; progress.Report(new ConversionProgress($"Finished converting {project.Name} at {DateTime.Now:HH:mm:ss}...")); } /// Perf: Keep lazy so that we don't keep an extra copy of all files in memory at once - private static async IAsyncEnumerable WithProjectFile(IProjectContentsConverter projectContentsConverter, TextReplacementConverter textReplacementConverter, + private static async IAsyncEnumerable WithProjectFileAsync(IProjectContentsConverter projectContentsConverter, TextReplacementConverter textReplacementConverter, ILanguageConversion languageConversion, ImmutableHashSet originalSourcePaths, IAsyncEnumerable convertProjectContents, (string Find, string Replace, bool FirstOnly)[] replacements) { @@ -158,7 +158,7 @@ private static (string Find, string Replace, bool FirstOnly) AddCompiledItemsReg } - private static async IAsyncEnumerable ConvertProjectContents( + private static async IAsyncEnumerable ConvertProjectContentsAsync( IProjectContentsConverter projectContentsConverter, ILanguageConversion languageConversion, IProgress progress, [EnumeratorCancellation] CancellationToken cancellationToken) { @@ -171,15 +171,15 @@ private static async IAsyncEnumerable ConvertProjectContents( var projectConversion = new ProjectConversion(projectContentsConverter, documentsToConvert, projectContentsConverter.SourceProject.AdditionalDocuments, languageConversion, cancellationToken); - var results = projectConversion.Convert(progress); + var results = projectConversion.ConvertAsync(progress); await foreach (var result in results.WithCancellation(cancellationToken)) yield return result; } - private async IAsyncEnumerable Convert(IProgress progress) + private async IAsyncEnumerable ConvertAsync(IProgress progress) { var phaseProgress = StartPhase(progress, "Phase 1 of 2:"); - var firstPassResults = _documentsToConvert.ParallelSelectAwait(d => FirstPassLoggedAsync(d, phaseProgress), Env.MaxDop, _cancellationToken); + var firstPassResults = _documentsToConvert.ParallelSelectAwaitAsync(d => FirstPassLoggedAsync(d, phaseProgress), Env.MaxDop, _cancellationToken); var (proj1, docs1) = await _projectContentsConverter.GetConvertedProjectAsync(await firstPassResults.ToArrayAsync(_cancellationToken)); var warnings = await GetProjectWarningsAsync(_projectContentsConverter.SourceProject, proj1); @@ -189,11 +189,11 @@ private async IAsyncEnumerable Convert(IProgress SecondPassLoggedAsync(d, phaseProgress), Env.MaxDop, _cancellationToken); + var secondPassResults = proj1.GetDocuments(docs1).ParallelSelectAwaitAsync(d => SecondPassLoggedAsync(d, phaseProgress), Env.MaxDop, _cancellationToken); await foreach (var result in secondPassResults.Select(CreateConversionResult).WithCancellation(_cancellationToken)) { yield return result; } - await foreach (var result in _projectContentsConverter.GetAdditionalConversionResults(_additionalDocumentsToConvert, _cancellationToken)) { + await foreach (var result in _projectContentsConverter.GetAdditionalConversionResultsAsync(_additionalDocumentsToConvert, _cancellationToken)) { yield return result; } } diff --git a/CodeConverter/Common/SolutionConverter.cs b/CodeConverter/Common/SolutionConverter.cs index d1cc42f74..76e1e9319 100644 --- a/CodeConverter/Common/SolutionConverter.cs +++ b/CodeConverter/Common/SolutionConverter.cs @@ -69,7 +69,7 @@ private SolutionConverter(string solutionFilePath, _textReplacementConverter = new TextReplacementConverter(fileSystem); } - public async IAsyncEnumerable Convert() + public async IAsyncEnumerable ConvertAsync() { var projectsToUpdateReferencesOnly = _projectsToConvert.First().Solution.Projects.Except(_projectsToConvert); var solutionResult = string.IsNullOrWhiteSpace(_sourceSolutionContents) ? Enumerable.Empty() : ConvertSolutionFile().Yield(); @@ -82,14 +82,14 @@ public async IAsyncEnumerable Convert() private async Task> ConvertProjectsAsync() { - return _projectsToConvert.ToAsyncEnumerable().SelectMany(ConvertProject); + return _projectsToConvert.ToAsyncEnumerable().SelectMany(ConvertProjectAsync); } - private IAsyncEnumerable ConvertProject(Project project) + private IAsyncEnumerable ConvertProjectAsync(Project project) { var replacements = _projectReferenceReplacements.ToArray(); _progress.Report(new ConversionProgress($"Begin converting {project.Name} at {DateTime.Now:HH:mm:ss}...")); - return ProjectConversion.ConvertProject(project, _languageConversion, _textReplacementConverter, _progress, _cancellationToken, replacements); + return ProjectConversion.ConvertProjectAsync(project, _languageConversion, _textReplacementConverter, _progress, _cancellationToken, replacements); } private IEnumerable UpdateProjectReferences(IEnumerable projectsToUpdateReferencesOnly) diff --git a/CodeConverter/Common/SymbolRenamer.cs b/CodeConverter/Common/SymbolRenamer.cs index e90f240df..0a687945a 100644 --- a/CodeConverter/Common/SymbolRenamer.cs +++ b/CodeConverter/Common/SymbolRenamer.cs @@ -24,10 +24,10 @@ public static string GetName(ISymbol m) { return m.Name; } - public static async Task PerformRenamesAsync(Project project, IReadOnlyCollection<(ISymbol Original, string NewName)> symbolsWithNewNames) + public static async Task PerformRenamesAsync(Project project, IEnumerable<(ISymbol Original, string NewName)> symbolsWithNewNames) { var solution = project.Solution; - foreach (var (originalSymbol, newName) in symbolsWithNewNames) { + foreach (var (originalSymbol, newName) in symbolsWithNewNames.OrderByDescending(s => s.Original.DeclaringSyntaxReferences.Select(x => x.Span.End).Max())) { project = solution.GetProject(project.Id); var compilation = await project.GetCompilationAsync(); ISymbol currentDeclaration = SymbolFinder.FindSimilarSymbols(originalSymbol, compilation).FirstOrDefault(); @@ -80,6 +80,7 @@ private static (ISymbol Original, string NewName)[] GetMethodSymbolsWithNewNames bool specialSymbolUsingName, bool caseSensitive) { var stringComparer = caseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase; +#pragma warning disable RS1024 // Compare symbols correctly - analzyer bug, I'm intentionally using my own comparer, not the default ambiguous one var methodsBySignature = methodSymbols .ToLookup(m => m.GetUnqualifiedMethodSignature(caseSensitive)) .Where(g => g.Count() > 1) @@ -91,6 +92,7 @@ private static (ISymbol Original, string NewName)[] GetMethodSymbolsWithNewNames !specialSymbolUsingName).ToArray(); return symbolsWithNewNames; }).ToArray(); +#pragma warning restore RS1024 // Compare symbols correctly foreach (var newMethodNames in methodsBySignature.Select(m => m.NewName)) { diff --git a/CodeConverter/GlobalUsings.cs b/CodeConverter/GlobalUsings.cs index dab492ccb..240589937 100644 --- a/CodeConverter/GlobalUsings.cs +++ b/CodeConverter/GlobalUsings.cs @@ -1,7 +1,13 @@ -global using VBasic = Microsoft.CodeAnalysis.VisualBasic; +global using Microsoft.CodeAnalysis; +global using ICSharpCode.CodeConverter.Util; +global using ICSharpCode.CodeConverter.Common; + +// Since so many names clash between CS and VB, it's best to use these aliases to be clear which one is meant +global using VBasic = Microsoft.CodeAnalysis.VisualBasic; global using CS = Microsoft.CodeAnalysis.CSharp; global using VBSyntax = Microsoft.CodeAnalysis.VisualBasic.Syntax; global using CSSyntax = Microsoft.CodeAnalysis.CSharp.Syntax; -global using ICSharpCode.CodeConverter.Common; -global using Microsoft.CodeAnalysis; -global using ICSharpCode.CodeConverter.Util; + +// For common unambiguous names, no need to qualify +global using VisualBasicSyntaxNode = Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxNode; +global using CSharpSyntaxNode = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode; diff --git a/CodeConverter/Util/FromRoslyn/ITypeSymbolExtensions.cs b/CodeConverter/Util/FromRoslyn/ITypeSymbolExtensions.cs index 9d7f06001..48a905a2d 100644 --- a/CodeConverter/Util/FromRoslyn/ITypeSymbolExtensions.cs +++ b/CodeConverter/Util/FromRoslyn/ITypeSymbolExtensions.cs @@ -89,7 +89,9 @@ private static HashSet GetOriginalInterfacesAndTheirBaseInterf this ITypeSymbol type, HashSet? symbols = null) { - symbols ??= new HashSet(SymbolEquivalenceComparer.Instance); +#pragma warning disable RS1024 // Compare symbols correctly - analyzer bug, this is the comparer the docs recommend + symbols ??= new(SymbolEqualityComparer.IncludeNullability); +#pragma warning restore RS1024 // Compare symbols correctly foreach (var interfaceType in type.Interfaces) { symbols.Add(interfaceType.OriginalDefinition); @@ -383,7 +385,7 @@ public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, return typeSymbol.AllInterfaces.Any(i => i.SpecialType == SpecialType.System_Collections_IEnumerable) && typeSymbol.GetBaseTypesAndThis() - .Union(typeSymbol.GetOriginalInterfacesAndTheirBaseInterfaces()) + .Union(typeSymbol.GetOriginalInterfacesAndTheirBaseInterfaces(), (IEqualityComparer)SymbolEqualityComparer.IncludeNullability) .SelectAccessibleMembers(WellKnownMemberNames.CollectionInitializerAddMethodName, within) .OfType() .Any(m => m.Parameters.Any()); @@ -393,7 +395,7 @@ public static bool CanSupportCollectionInitializer(this ITypeSymbol typeSymbol, { if (typeSymbol != null) { var expressionOfT = compilation.ExpressionOfTType(); - if (typeSymbol.OriginalDefinition.Equals(expressionOfT)) { + if (typeSymbol.OriginalDefinition.Equals(expressionOfT, SymbolEqualityComparer.IncludeNullability)) { var typeArgument = ((INamedTypeSymbol)typeSymbol).TypeArguments[0]; return typeArgument as INamedTypeSymbol; } diff --git a/CodeConverter/Util/FromRoslyn/NamedTypeSymbolExtensions.cs b/CodeConverter/Util/FromRoslyn/NamedTypeSymbolExtensions.cs index 2183dddf9..9a01e7531 100644 --- a/CodeConverter/Util/FromRoslyn/NamedTypeSymbolExtensions.cs +++ b/CodeConverter/Util/FromRoslyn/NamedTypeSymbolExtensions.cs @@ -15,7 +15,7 @@ public static IMethodSymbol GetDesignerGeneratedInitializeComponentOrNull(this I return null; } - if (!type.GetAttributes().Where(a => Equals(a.AttributeClass, designerGeneratedAttribute)).Any()) { + if (!type.GetAttributes().Where(a => SymbolEqualityComparer.IncludeNullability.Equals(a.AttributeClass, designerGeneratedAttribute)).Any()) { return null; } diff --git a/CodeConverter/Util/FromRoslyn/RoslynISymbolExtensions.cs b/CodeConverter/Util/FromRoslyn/RoslynISymbolExtensions.cs index 95fd3e718..ea157040b 100644 --- a/CodeConverter/Util/FromRoslyn/RoslynISymbolExtensions.cs +++ b/CodeConverter/Util/FromRoslyn/RoslynISymbolExtensions.cs @@ -369,7 +369,7 @@ private static bool IsNestedWithinOriginalContainingType( // nested type of that owner and I'm allowed access to everything inside of it. var current = withinType.OriginalDefinition; while (current != null) { - if (current.Equals(originalContainingType)) { + if (current.Equals(originalContainingType, SymbolEqualityComparer.IncludeNullability)) { return true; } diff --git a/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.EquivalenceVisitor.cs b/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.EquivalenceVisitor.cs index 13e391ef9..0d47cf870 100644 --- a/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.EquivalenceVisitor.cs +++ b/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.EquivalenceVisitor.cs @@ -555,7 +555,7 @@ private bool PropertiesAreEquivalent(IPropertySymbol x, IPropertySymbol y, Dicti // equality. This will properly handle things like the VB case where two // anonymous types will be considered the same if they have properties that // differ in casing. - if (x.Equals(y)) + if (x.Equals(y, SymbolEqualityComparer.IncludeNullability)) { return true; } diff --git a/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.GetHashCodeVisitor.cs b/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.GetHashCodeVisitor.cs index af45f8756..5373ff724 100644 --- a/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.GetHashCodeVisitor.cs +++ b/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.GetHashCodeVisitor.cs @@ -317,7 +317,7 @@ private static int CombineHashCodes(IRangeVariableSymbol x, int currentHash) private static int CombineHashCodes(IPreprocessingSymbol x, int currentHash) { - return Hash.Combine(x.GetHashCode(), currentHash); + return Hash.Combine(SymbolEqualityComparer.IncludeNullability.GetHashCode(x), currentHash); } } } \ No newline at end of file diff --git a/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.cs b/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.cs index 69f21a2c7..12f9b2cfd 100644 --- a/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.cs +++ b/CodeConverter/Util/FromRoslyn/SymbolEquivalenceComparer.cs @@ -182,12 +182,12 @@ private static SymbolKind GetKindAndUnwrapAlias(ref ISymbol symbol) private static bool IsConstructedFromSelf(INamedTypeSymbol symbol) { - return symbol.Equals(symbol.ConstructedFrom); + return symbol.Equals(symbol.ConstructedFrom, SymbolEqualityComparer.IncludeNullability); } private static bool IsConstructedFromSelf(IMethodSymbol symbol) { - return symbol.Equals(symbol.ConstructedFrom); + return symbol.Equals(symbol.ConstructedFrom, SymbolEqualityComparer.IncludeNullability); } private static bool IsObjectType(ISymbol symbol) diff --git a/CodeConverter/Util/IAssemblySymbolExtensions.cs b/CodeConverter/Util/IAssemblySymbolExtensions.cs index 21b0d3d10..f48475f0e 100644 --- a/CodeConverter/Util/IAssemblySymbolExtensions.cs +++ b/CodeConverter/Util/IAssemblySymbolExtensions.cs @@ -5,7 +5,7 @@ internal static class IAssemblySymbolExtensions public static bool IsSameAssemblyOrHasFriendAccessTo(this IAssemblySymbol assembly, IAssemblySymbol toAssembly) { return - Equals(assembly, toAssembly) || + SymbolEqualityComparer.IncludeNullability.Equals(assembly, toAssembly) || (assembly.IsInteractive && toAssembly.IsInteractive) || toAssembly.GivesAccessTo(assembly); } diff --git a/CodeConverter/Util/ITypeSymbolExtensions.cs b/CodeConverter/Util/ITypeSymbolExtensions.cs index 9b7c320e1..a95d5d761 100644 --- a/CodeConverter/Util/ITypeSymbolExtensions.cs +++ b/CodeConverter/Util/ITypeSymbolExtensions.cs @@ -13,7 +13,7 @@ public static bool IsDelegateReferencableByName(this ITypeSymbol t) public static bool ContainsMember(this ITypeSymbol potentialContainer, ISymbol potentialMember) { - return potentialContainer.FollowProperty(t => t.BaseType).Contains(potentialMember.ContainingType); + return potentialContainer.FollowProperty(t => t.BaseType).Contains(potentialMember.ContainingType, SymbolEqualityComparer.IncludeNullability); } public static bool HasCsKeyword(this ITypeSymbol typeSymbol) diff --git a/CodeConverter/VB/CSToVBConversion.cs b/CodeConverter/VB/CSToVBConversion.cs index b929322ed..90a1c75a1 100644 --- a/CodeConverter/VB/CSToVBConversion.cs +++ b/CodeConverter/VB/CSToVBConversion.cs @@ -1,6 +1,7 @@ using System.Globalization; using System.Text; using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; using SyntaxKind = Microsoft.CodeAnalysis.CSharp.SyntaxKind; namespace ICSharpCode.CodeConverter.VB; @@ -145,17 +146,16 @@ private static string TweakOutputPath(string s) public bool CanBeContainedByMethod(SyntaxNode node) { return node is CSSyntax.IncompleteMemberSyntax || - node is CSSyntax.StatementSyntax || + node is CSSyntax.StatementSyntax and not CSSyntax.LocalFunctionStatementSyntax || node.ContainsSkippedText || node.IsMissing || - ParsedAsFieldButCouldBeLocalVariableDeclaration(node); ; + ParsedAsFieldButCouldBeLocalVariableDeclaration(node); } public bool MustBeContainedByClass(SyntaxNode node) { return node is CSSyntax.BaseMethodDeclarationSyntax || node is CSSyntax.BaseFieldDeclarationSyntax || - node is CSSyntax.BasePropertyDeclarationSyntax || - node is CSSyntax.GlobalStatementSyntax; //https://github.com/icsharpcode/CodeConverter/issues/825 + node is CSSyntax.BasePropertyDeclarationSyntax || node is CSSyntax.LocalFunctionStatementSyntax; } private static bool ParsedAsFieldButCouldBeLocalVariableDeclaration(SyntaxNode node) diff --git a/CodeConverter/VB/CSToVBProjectContentsConverter.cs b/CodeConverter/VB/CSToVBProjectContentsConverter.cs index 9cf6186fc..1ea2c923e 100644 --- a/CodeConverter/VB/CSToVBProjectContentsConverter.cs +++ b/CodeConverter/VB/CSToVBProjectContentsConverter.cs @@ -67,7 +67,7 @@ public async Task SingleFirstPassAsync(Document document) return _convertedVbProject.WithDocuments(firstPassResults); } - public async IAsyncEnumerable GetAdditionalConversionResults(IReadOnlyCollection additionalDocumentsToConvert, [EnumeratorCancellation] CancellationToken cancellationToken) + public async IAsyncEnumerable GetAdditionalConversionResultsAsync(IReadOnlyCollection additionalDocumentsToConvert, [EnumeratorCancellation] CancellationToken cancellationToken) { yield break; } diff --git a/CodeConverter/VB/ClashingMemberRenamer.cs b/CodeConverter/VB/ClashingMemberRenamer.cs index ee7a39275..00962cc9e 100644 --- a/CodeConverter/VB/ClashingMemberRenamer.cs +++ b/CodeConverter/VB/ClashingMemberRenamer.cs @@ -37,7 +37,9 @@ public static IEnumerable> GetLocalSymbolSets(INamespaceOrT } private static IEnumerable<(ISymbol Original, string NewName)> GetUniqueNamesForSymbolSet(IEnumerable symbols) { - var membersByCaseInsensitiveName = symbols.ToLookup(SymbolRenamer.GetName, m => m, StringComparer.OrdinalIgnoreCase); +#pragma warning disable RS1024 // Compare symbols correctly - analyzer bug, I'm using a string not the default ambiguous comparer + var membersByCaseInsensitiveName = symbols.ToLookup(SymbolRenamer.GetName, StringComparer.OrdinalIgnoreCase); +#pragma warning restore RS1024 // Compare symbols correctly var names = new HashSet(membersByCaseInsensitiveName.Select(ms => ms.Key), StringComparer.OrdinalIgnoreCase); var symbolsWithNewNames = membersByCaseInsensitiveName.Where(ms => ms.Count() > 1) diff --git a/CodeConverter/VB/CommonConversions.cs b/CodeConverter/VB/CommonConversions.cs index 3044a4894..61b138e50 100644 --- a/CodeConverter/VB/CommonConversions.cs +++ b/CodeConverter/VB/CommonConversions.cs @@ -532,7 +532,7 @@ private string AdjustIfEventIdentifier(string valueText, CS.CSharpSyntaxNode par } var operation = _semanticModel.GetAncestorOperationOrNull(parent); - if (operation == null || !operation.Event.Equals(symbol) || operation.Parent is IEventAssignmentOperation || + if (operation == null || !operation.Event.Equals(symbol, SymbolEqualityComparer.IncludeNullability) || operation.Parent is IEventAssignmentOperation || operation.Parent is IRaiseEventOperation || operation.Parent is IInvocationOperation || operation.Parent is IConditionalAccessOperation cao && cao.WhenNotNull is IInvocationOperation) { return valueText; diff --git a/CodeConverter/VB/NodesVisitor.cs b/CodeConverter/VB/NodesVisitor.cs index 68a72a536..995aa18fd 100644 --- a/CodeConverter/VB/NodesVisitor.cs +++ b/CodeConverter/VB/NodesVisitor.cs @@ -463,7 +463,9 @@ private ImplementsClauseSyntax CreateImplementsClauseSyntaxOrNull(ISymbol member var explicitImplementors = memberInfo.ExplicitInterfaceImplementations(); if (explicitImplementors.Any()) { //https://github.com/icsharpcode/CodeConverter/issues/492 +#pragma warning disable RS1024 // Compare symbols correctly - analyzer bug, I'm using a string not the default ambiguous comparer var memberNames = memberInfo.ContainingType.GetMembers().ToLookup(s => UndottedMemberName(s.Name), StringComparer.OrdinalIgnoreCase); +#pragma warning restore RS1024 // Compare symbols correctly string explicitMemberName = UndottedMemberName(memberInfo.Name); var hasDuplicateNames = memberNames[explicitMemberName].Count() > 1; if (hasDuplicateNames) id = SyntaxFactory.Identifier(NameGenerator.GenerateUniqueName(explicitMemberName, n => !memberNames.Contains(n) && _addedNames.Add(n))); @@ -472,7 +474,7 @@ private ImplementsClauseSyntax CreateImplementsClauseSyntaxOrNull(ISymbol member var baseClassesAndInterfaces = containingType.GetAllBaseClassesAndInterfaces(true); explicitImplementors = baseClassesAndInterfaces.Except(new[] { containingType }) .SelectMany(t => t.GetMembers().Where(m => memberInfo.Name.EndsWith(m.Name, StringComparison.InvariantCulture))) - .Where(m => containingType.FindImplementationForInterfaceMember(m)?.Equals(memberInfo) == true) + .Where(m => containingType.FindImplementationForInterfaceMember(m)?.Equals(memberInfo, SymbolEqualityComparer.IncludeNullability) == true) .ToImmutableArray(); } diff --git a/CodeConverter/VB/SemanticModelSymbolSetExtensions.cs b/CodeConverter/VB/SemanticModelSymbolSetExtensions.cs index 16a36c7b7..4170a3c42 100644 --- a/CodeConverter/VB/SemanticModelSymbolSetExtensions.cs +++ b/CodeConverter/VB/SemanticModelSymbolSetExtensions.cs @@ -6,7 +6,7 @@ internal static class SemanticModelSymbolSetExtensions public static IEnumerable> GetCsSymbolsPerScope(this SemanticModel semanticModel, ISymbol symbol) { - return GetCsLocalSymbolsPerScope(semanticModel, symbol).Select(y => y.Union(symbol.Yield())); + return GetCsLocalSymbolsPerScope(semanticModel, symbol).Select(y => y.Union(symbol.Yield(), SymbolEqualityComparer.IncludeNullability)); } /// diff --git a/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj b/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj index 4d1390e32..086036d61 100644 --- a/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj +++ b/CommandLine/CodeConv.NetFramework/CodeConv.NetFramework.csproj @@ -10,13 +10,12 @@ - + - - - - - + + + + diff --git a/CommandLine/CodeConv.Shared/MSBuildWorkspaceConverter.cs b/CommandLine/CodeConv.Shared/MSBuildWorkspaceConverter.cs index 9b8f7a9c9..2ae7d48f0 100644 --- a/CommandLine/CodeConv.Shared/MSBuildWorkspaceConverter.cs +++ b/CommandLine/CodeConv.Shared/MSBuildWorkspaceConverter.cs @@ -63,7 +63,7 @@ public async IAsyncEnumerable ConvertProjectsWhereAsync(Func

p.Language == languageNameToConvert && shouldConvertProject(p)).ToArray(); - var results = SolutionConverter.CreateFor(languageConversion, projectsToConvert, progress, token).Convert(); + var results = SolutionConverter.CreateFor(languageConversion, projectsToConvert, progress, token).ConvertAsync(); await foreach (var r in results.WithCancellation(token)) yield return r; } @@ -98,7 +98,7 @@ private async Task GetCompilationErrorsAsync( IEnumerable projectsToConvert) { var workspaceErrors = (await _workspace.GetValueAsync()).Diagnostics.GetErrorString(); - var errors = await projectsToConvert.ParallelSelectAwait(async x => { + var errors = await projectsToConvert.ParallelSelectAwaitAsync(async x => { var c = await x.GetCompilationAsync() ?? throw new InvalidOperationException($"Compilation could not be created for {x.Language}"); return new[] { CompilationWarnings.WarningsForCompilation(c, c.AssemblyName) }; }, Env.MaxDop).ToArrayAsync(); diff --git a/CommandLine/CodeConv/CodeConv.csproj b/CommandLine/CodeConv/CodeConv.csproj index adaacfbd3..7c753a93e 100644 --- a/CommandLine/CodeConv/CodeConv.csproj +++ b/CommandLine/CodeConv/CodeConv.csproj @@ -28,7 +28,7 @@ For a nugetted dll, web converter or visual studio extension, see https://github - + @@ -37,7 +37,7 @@ For a nugetted dll, web converter or visual studio extension, see https://github all runtime; build; native; contentfiles; analyzers - + diff --git a/Func/Func.csproj b/Func/Func.csproj index ee8935a6f..a77321495 100644 --- a/Func/Func.csproj +++ b/Func/Func.csproj @@ -14,13 +14,13 @@ - + - - - - - + + + + + diff --git a/Tests/CSharp/ExpressionTests/BinaryExpressionTests.cs b/Tests/CSharp/ExpressionTests/BinaryExpressionTests.cs index 38611c96d..3e0f1e85a 100644 --- a/Tests/CSharp/ExpressionTests/BinaryExpressionTests.cs +++ b/Tests/CSharp/ExpressionTests/BinaryExpressionTests.cs @@ -116,7 +116,7 @@ private void TestMethod() x += 1d; x -= 2d; x *= 3d; - x = x / 4L; + x = (double)(x / 4L); x = Math.Pow(x, 5d); } }"); diff --git a/Tests/CSharp/ExpressionTests/ExpressionTests.cs b/Tests/CSharp/ExpressionTests/ExpressionTests.cs index f2b5309ad..b1ec992f0 100644 --- a/Tests/CSharp/ExpressionTests/ExpressionTests.cs +++ b/Tests/CSharp/ExpressionTests/ExpressionTests.cs @@ -1061,7 +1061,7 @@ private partial class Rec private Rec TestMethod(string str) { - int length = str?.Length ?? -1; + int length = (str?.Length) ?? -1; Console.WriteLine(length); Console.ReadKey(); return new Rec()?.Prop?.Prop?.Prop; @@ -2096,7 +2096,7 @@ internal static partial class Module1 { public static void Main() { - short x = true ? 50 : 100; + short x = true ? (short)50 : (short)100; } } "); diff --git a/Tests/CSharp/ExpressionTests/XmlExpressionTests.cs b/Tests/CSharp/ExpressionTests/XmlExpressionTests.cs index 59af6c59f..8c853c7f7 100644 --- a/Tests/CSharp/ExpressionTests/XmlExpressionTests.cs +++ b/Tests/CSharp/ExpressionTests/XmlExpressionTests.cs @@ -24,7 +24,7 @@ internal partial class TestClass private void TestMethod() { string hello = ""Hello""; - XElement x = new XElement(""h1"", hello); + var x = new XElement(""h1"", hello); } }"); } @@ -46,7 +46,7 @@ private void TestMethod() { int var1 = 1; int var2 = 2; - XElement x = new XElement(""h1"", var1, var2, new XElement(""span"", var2, var1)); + var x = new XElement(""h1"", var1, var2, new XElement(""span"", var2, var1)); } }"); } @@ -114,9 +114,9 @@ internal partial class TestClass { private void TestMethod() { - XDocument 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"", ""\r\n An in-depth look at creating applications\r\n with "", new XElement(""technology"", ""XML""), "". For\r\n "", new XElement(""audience"", ""beginners""), "" or\r\n "", new XElement(""audience"", ""advanced""), "" developers.\r\n "")), 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"", ""\r\n Get the expert insights, practical code samples,\r\n and best practices you need\r\n to advance your expertise with "", new XElement(""technology"", ""Visual\r\n Basic .NET""), "".\r\n Learn how to create faster, more reliable applications\r\n based on professional,\r\n pragmatic guidance by today's top "", new XElement(""audience"", ""developers""), "".\r\n "")))); - XElement 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(""h2"", ""Description""), TransformDescription((string)book.Elements(""Description"").ElementAtOrDefault(0)), new XElement(""hr"")))); + 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"", ""\r\n An in-depth look at creating applications\r\n with "", new XElement(""technology"", ""XML""), "". For\r\n "", new XElement(""audience"", ""beginners""), "" or\r\n "", new XElement(""audience"", ""advanced""), "" developers.\r\n "")), 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"", ""\r\n Get the expert insights, practical code samples,\r\n and best practices you need\r\n to advance your expertise with "", new XElement(""technology"", ""Visual\r\n Basic .NET""), "".\r\n Learn how to create faster, more reliable applications\r\n based on professional,\r\n pragmatic guidance by today's top "", new XElement(""audience"", ""developers""), "".\r\n "")))); + 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(""h2"", ""Description""), TransformDescription((string)book.Elements(""Description"").ElementAtOrDefault(0)), new XElement(""hr"")))); } public string TransformDescription(string s) @@ -145,8 +145,8 @@ internal partial class TestClass { private void TestMethod() { - XElement b = new XElement(""someXmlTag""); - XElement c = new XElement(""someXmlTag"", new XElement(""bla"", new XAttribute(""anAttribute"", ""itsValue""), ""tata""), new XElement(""someContent"", ""tata"")); + var b = new XElement(""someXmlTag""); + var c = new XElement(""someXmlTag"", new XElement(""bla"", new XAttribute(""anAttribute"", ""itsValue""), ""tata""), new XElement(""someContent"", ""tata"")); } }"); } @@ -168,7 +168,7 @@ internal partial class TestClass private void TestMethod() { const string value1 = ""something""; - XElement xElement = new XElement(""Elem1"", new XAttribute(""Attr1"", value1), new XAttribute(""Attr2"", 100)); + var xElement = new XElement(""Elem1"", new XAttribute(""Attr1"", value1), new XAttribute(""Attr2"", 100)); } }"); } @@ -188,7 +188,7 @@ internal partial class TestClass { private void TestMethod() { - XElement xElement = new XElement(""Elem1"", new XAttribute(""Attr1"", ""something"")); + var xElement = new XElement(""Elem1"", new XAttribute(""Attr1"", ""something"")); } }"); } @@ -210,7 +210,7 @@ internal partial class TestClass { private void TestMethod() { - XElement xDocument = new XElement(""Test""); + var xDocument = new XElement(""Test""); var elements1 = xDocument.Elements(""Something"").SingleOrDefault()?.Elements(""SomethingElse""); } }"); @@ -276,10 +276,10 @@ internal static partial class Module1 public static void Main() { // Create element by using the default global XML namespace. - XElement inner = XmlImports.Apply(new XElement(XmlImports.Default + ""innerElement"")); + var inner = XmlImports.Apply(new XElement(XmlImports.Default + ""innerElement"")); // Create element by using both the default global XML namespace and the namespace identified with the ""ns"" prefix. - XElement outer = XmlImports.Apply(new XElement(XmlImports.ns + ""outer"", new XElement(XmlImports.ns + ""innerElement""), new XElement(XmlImports.Default + ""siblingElement""), inner)); + var outer = XmlImports.Apply(new XElement(XmlImports.ns + ""outer"", new XElement(XmlImports.ns + ""innerElement""), new XElement(XmlImports.Default + ""siblingElement""), inner)); // Display element to see its final form. Console.WriteLine(outer); diff --git a/Tests/CSharp/MemberTests/MemberTests.cs b/Tests/CSharp/MemberTests/MemberTests.cs index bbe906418..5108e883c 100644 --- a/Tests/CSharp/MemberTests/MemberTests.cs +++ b/Tests/CSharp/MemberTests/MemberTests.cs @@ -582,10 +582,7 @@ public virtual int RenamedReadOnlyProperty } } - int IClass.ReadOnlyProp // Comment moves because this line gets split - { - get => RenamedReadOnlyProperty; - } + int IClass.ReadOnlyProp { get => RenamedReadOnlyProperty; } // Comment moves because this line gets split public virtual int get_RenamedWriteOnlyPropParam(int i) { @@ -610,10 +607,7 @@ public virtual int RenamedWriteOnlyProperty } } - int IClass.WriteOnlyProp // Comment moves because this line gets split - { - set => RenamedWriteOnlyProperty = value; - } + int IClass.WriteOnlyProp { set => RenamedWriteOnlyProperty = value; } // Comment moves because this line gets split }"); } @@ -1896,11 +1890,7 @@ private int doFoo() int IFoo.DoFoo() => doFoo(); private int prop { get; set; } - int IFoo.Prop - { - get => prop; - set => prop = value; - } + int IFoo.Prop { get => prop; set => prop = value; } private int Consumer() { @@ -1971,11 +1961,7 @@ protected internal virtual int doFoo() int IFoo.DoFoo() => doFoo(); protected internal virtual int prop { get; set; } - int IFoo.Prop - { - get => prop; - set => prop = value; - } + int IFoo.Prop { get => prop; set => prop = value; } } public partial class Foo : BaseFoo @@ -2053,10 +2039,7 @@ public partial interface IFoo public abstract partial class BaseFoo : IUserContext { protected internal string ConnectedGroupID { get; private set; } - string IUserContext.GroupID - { - get => ConnectedGroupID; - } + string IUserContext.GroupID { get => ConnectedGroupID; } } public partial class Foo : BaseFoo, IFoo @@ -2069,10 +2052,7 @@ public partial class Foo : BaseFoo, IFoo } } - string IFoo.ConnectedGroupId // Comment moves because this line gets split - { - get => ConnectedGroupID; - } + string IFoo.ConnectedGroupId { get => ConnectedGroupID; } // Comment moves because this line gets split private string Consumer() { @@ -2161,17 +2141,9 @@ public partial interface IBar public partial class FooBar : IFoo, IBar { public int Foo { get; set; } - int IFoo.FooBarProp - { - get => Foo; - set => Foo = value; - } + int IFoo.FooBarProp { get => Foo; set => Foo = value; } public int Bar { get; set; } - int IBar.FooBarProp - { - get => Bar; - set => Bar = value; - } + int IBar.FooBarProp { get => Bar; set => Bar = value; } }"); } @@ -2236,11 +2208,7 @@ public partial interface IFoo public partial class Foo : TestNamespace.IFoo { public int FooPropRenamed { get; set; } - int TestNamespace.IFoo.FooProp - { - get => FooPropRenamed; - set => FooPropRenamed = value; - } + int TestNamespace.IFoo.FooProp { get => FooPropRenamed; set => FooPropRenamed = value; } }"); } @@ -2321,11 +2289,7 @@ public partial interface IFoo public partial class Foo : IFoo { public int FooPropRenamed { get; set; } - int IFoo.FooProp - { - get => FooPropRenamed; - set => FooPropRenamed = value; - } + int IFoo.FooProp { get => FooPropRenamed; set => FooPropRenamed = value; } } public partial class FooConsumer @@ -2504,11 +2468,7 @@ public partial interface IFoo public partial class Foo : IFoo { public int FooPropRenamed { get; set; } - int IFoo.FooProp - { - get => FooPropRenamed; - set => FooPropRenamed = value; - } + int IFoo.FooProp { get => FooPropRenamed; set => FooPropRenamed = value; } } public partial class FooConsumer @@ -2599,11 +2559,7 @@ public partial interface IFoo public partial class Foo : IFoo { public int FooPropRenamed { get; set; } - int IFoo.FooProp - { - get => FooPropRenamed; - set => FooPropRenamed = value; - } + int IFoo.FooProp { get => FooPropRenamed; set => FooPropRenamed = value; } } public partial class FooConsumer @@ -2701,10 +2657,7 @@ public int MyClassDoFooRenamed } } - int IFoo.DoFoo - { - get => DoFooRenamed; - } + int IFoo.DoFoo { get => DoFooRenamed; } public virtual int DoFooRenamed // Comment ends up out of order, but attached to correct method { @@ -2722,10 +2675,7 @@ public int MyClassDoBarRenamed } } - int IFoo.DoBar - { - set => DoBarRenamed = value; - } + int IFoo.DoBar { set => DoBarRenamed = value; } public virtual int DoBarRenamed // Comment ends up out of order, but attached to correct method { @@ -2889,16 +2839,8 @@ public partial interface IBar public partial class Foo : IFoo, IBar { private int ExplicitProp { get; set; } - int IFoo.ExplicitProp - { - get => ExplicitProp; - set => ExplicitProp = value; - } - int IBar.ExplicitProp - { - get => ExplicitProp; - set => ExplicitProp = value; - } + int IFoo.ExplicitProp { get => ExplicitProp; set => ExplicitProp = value; } + int IBar.ExplicitProp { get => ExplicitProp; set => ExplicitProp = value; } }"); } @@ -2933,17 +2875,9 @@ public partial interface IBar public abstract partial class Foo : IFoo, IBar { protected abstract int ExplicitPropRenamed1 { get; set; } - int IFoo.ExplicitProp - { - get => ExplicitPropRenamed1; - set => ExplicitPropRenamed1 = value; - } + int IFoo.ExplicitProp { get => ExplicitPropRenamed1; set => ExplicitPropRenamed1 = value; } protected abstract int ExplicitPropRenamed2 { get; set; } - int IBar.ExplicitProp - { - get => ExplicitPropRenamed2; - set => ExplicitPropRenamed2 = value; - } + int IBar.ExplicitProp { get => ExplicitPropRenamed2; set => ExplicitPropRenamed2 = value; } }"); } @@ -2999,11 +2933,7 @@ protected override void OnSave() void IFoo.Save() => OnSave(); protected override int MyProp { get; set; } = 6; - int IFoo.Prop - { - get => MyProp; - set => MyProp = value; - } + int IFoo.Prop { get => MyProp; set => MyProp = value; } }"); } @@ -3055,16 +2985,8 @@ public virtual void Save() void IBar.OnSave() => Save(); public virtual int A { get; set; } - int IFoo.A - { - get => A; - set => A = value; - } - int IBar.B - { - get => A; - set => A = value; - } + int IFoo.A { get => A; set => A = value; } + int IBar.B { get => A; set => A = value; } }"); } @@ -3120,11 +3042,7 @@ public partial class Foo : BaseFoo, IFoo void IFoo.Save() => OnSave(); public new int MyProp { get; set; } = 6; - int IFoo.Prop - { - get => MyProp; - set => MyProp = value; - } + int IFoo.Prop { get => MyProp; set => MyProp = value; } }"); } @@ -3175,16 +3093,8 @@ private int ExplicitProp } } - int IFoo.ExplicitProp - { - get => ExplicitProp; - set => ExplicitProp = value; - } - int IBar.ExplicitProp // Comment moves because this line gets split - { - get => ExplicitProp; - set => ExplicitProp = value; - } + int IFoo.ExplicitProp { get => ExplicitProp; set => ExplicitProp = value; } + int IBar.ExplicitProp { get => ExplicitProp; set => ExplicitProp = value; } // Comment moves because this line gets split }"); } @@ -3275,16 +3185,8 @@ internal virtual int FriendProp } } - int IFoo.FriendProp - { - get => FriendProp; - set => FriendProp = value; - } - int IBar.FriendProp // Comment moves because this line gets split - { - get => FriendProp; - set => FriendProp = value; - } + int IFoo.FriendProp { get => FriendProp; set => FriendProp = value; } + int IBar.FriendProp { get => FriendProp; set => FriendProp = value; } // Comment moves because this line gets split protected void ProtectedSub() { @@ -3355,16 +3257,9 @@ public partial interface IFoo public partial class Foo : IFoo { public int ExplicitPropRenamed { get; set; } - int IFoo.ExplicitProp - { - get => ExplicitPropRenamed; - set => ExplicitPropRenamed = value; - } + int IFoo.ExplicitProp { get => ExplicitPropRenamed; set => ExplicitPropRenamed = value; } public int ExplicitRenamedReadOnlyProp { get; private set; } - int IFoo.ExplicitReadOnlyProp - { - get => ExplicitRenamedReadOnlyProp; - } + int IFoo.ExplicitReadOnlyProp { get => ExplicitRenamedReadOnlyProp; } private void Consumer() { @@ -3404,14 +3299,8 @@ public partial interface IBar public partial class Foo : IFoo, IBar { public int ExplicitPropRenamed { get; private set; } - int IFoo.ExplicitProp - { - get => ExplicitPropRenamed; - } - int IBar.ExplicitProp - { - get => ExplicitPropRenamed; - } + int IFoo.ExplicitProp { get => ExplicitPropRenamed; } + int IBar.ExplicitProp { get => ExplicitPropRenamed; } }"); } @@ -3454,14 +3343,8 @@ public int ExplicitPropRenamed } } - int IFoo.ExplicitProp - { - set => ExplicitPropRenamed = value; - } - int IBar.ExplicitProp // Comment moves because this line gets split - { - set => ExplicitPropRenamed = value; - } + int IFoo.ExplicitProp { set => ExplicitPropRenamed = value; } + int IBar.ExplicitProp { set => ExplicitPropRenamed = value; } // Comment moves because this line gets split }"); } diff --git a/Tests/CSharp/StatementTests/LoopStatementTests.cs b/Tests/CSharp/StatementTests/LoopStatementTests.cs index 254252ed4..2e16a802c 100644 --- a/Tests/CSharp/StatementTests/LoopStatementTests.cs +++ b/Tests/CSharp/StatementTests/LoopStatementTests.cs @@ -196,9 +196,9 @@ internal partial class ForEnumAsync { public void PrintLoop(MyEnum startIndex, MyEnum endIndex, MyEnum step) { - for (MyEnum i = startIndex, loopTo = endIndex; step >= 0 ? i <= loopTo : i >= loopTo; i += (int)step) + for (MyEnum i = startIndex, loopTo = endIndex; (int)step >= 0 ? i <= loopTo : i >= loopTo; i += (int)step) Debug.WriteLine(i); - for (MyEnum i2 = startIndex, loopTo1 = endIndex; step >= 0 ? i2 <= loopTo1 : i2 >= loopTo1; i2 += (int)step) + for (MyEnum i2 = startIndex, loopTo1 = endIndex; (int)step >= 0 ? i2 <= loopTo1 : i2 >= loopTo1; i2 += (int)step) Debug.WriteLine(i2); for (MyEnum i3 = startIndex, loopTo2 = endIndex; i3 <= loopTo2; i3 += 3) Debug.WriteLine(i3); diff --git a/Tests/LanguageAgnostic/ParallelSelectAwaitTests.cs b/Tests/LanguageAgnostic/ParallelSelectAwaitTests.cs index c7268999e..0e8223057 100644 --- a/Tests/LanguageAgnostic/ParallelSelectAwaitTests.cs +++ b/Tests/LanguageAgnostic/ParallelSelectAwaitTests.cs @@ -14,7 +14,7 @@ public class ParallelSelectAwaitTests [Fact] public async Task ExceptionDoesNotHaltPipelineAsync() { - var asyncEnumerable = Input.ParallelSelectAwait(async i => { + var asyncEnumerable = Input.ParallelSelectAwaitAsync(async i => { await Task.Delay(1); return i > 3 ? i : throw new ObjectDisposedException("Original"); }, MaxDop); @@ -25,7 +25,7 @@ public async Task ExceptionDoesNotHaltPipelineAsync() [Fact] public async Task ExceptionDoesNotHaltPipelineSyncAsync() { - var asyncEnumerable = Input.ParallelSelectAwait( + var asyncEnumerable = Input.ParallelSelectAwaitAsync( async i => i > 3 ? i : throw new ObjectDisposedException("Original") , MaxDop ); @@ -36,7 +36,7 @@ public async Task ExceptionDoesNotHaltPipelineSyncAsync() [Fact] public async Task AllElementsProcessedAsync() { - var array = await Input.ParallelSelectAwait( + var array = await Input.ParallelSelectAwaitAsync( async i => i , MaxDop ).ToArrayAsync(); diff --git a/Tests/LanguageAgnostic/SolutionFileTextEditorTests.cs b/Tests/LanguageAgnostic/SolutionFileTextEditorTests.cs index 32c6d6e91..41397ece3 100644 --- a/Tests/LanguageAgnostic/SolutionFileTextEditorTests.cs +++ b/Tests/LanguageAgnostic/SolutionFileTextEditorTests.cs @@ -576,7 +576,7 @@ private Project AddTestProject(string projFileName, string projDirName, string p private static async Task GetConvertedCodeAsync(SolutionConverter slnConverter, Project referencingProject) { - var conversionResult = await slnConverter.Convert() + var conversionResult = await slnConverter.ConvertAsync() .SingleAsync(result => result.SourcePathOrNull == referencingProject.FilePath); return conversionResult.ConvertedCode; diff --git a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertCSharpConsoleAppOnly/ConsoleApp2/AnotherSharedNamespaceClass.vb b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertCSharpConsoleAppOnly/ConsoleApp2/AnotherSharedNamespaceClass.vb index 40e2f46dc..3ec132a02 100644 --- a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertCSharpConsoleAppOnly/ConsoleApp2/AnotherSharedNamespaceClass.vb +++ b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertCSharpConsoleAppOnly/ConsoleApp2/AnotherSharedNamespaceClass.vb @@ -1,3 +1,4 @@ + Namespace NamespaceSharedWithOtherAssembly Friend Class AnotherSharedNamespaceClass End Class diff --git a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertCSharpConsoleAppOnly/ConsoleApp2/Properties/AssemblyInfo.vb b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertCSharpConsoleAppOnly/ConsoleApp2/Properties/AssemblyInfo.vb index a6d1d0a6b..971b5e0bd 100644 --- a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertCSharpConsoleAppOnly/ConsoleApp2/Properties/AssemblyInfo.vb +++ b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertCSharpConsoleAppOnly/ConsoleApp2/Properties/AssemblyInfo.vb @@ -1,7 +1,6 @@ Imports System.Reflection Imports System.Runtime.InteropServices - ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. diff --git a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/CSharpNetStandardLib/Class1.vb b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/CSharpNetStandardLib/Class1.vb index b2c379f9b..2d427f4e0 100644 --- a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/CSharpNetStandardLib/Class1.vb +++ b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/CSharpNetStandardLib/Class1.vb @@ -1,3 +1,4 @@ + Namespace CSharpNetStandardLib Public Class Class1 Public Sub MethodOnlyDifferingInTypeParameterCount() diff --git a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/ConsoleApp2/AnotherSharedNamespaceClass.vb b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/ConsoleApp2/AnotherSharedNamespaceClass.vb index 40e2f46dc..3ec132a02 100644 --- a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/ConsoleApp2/AnotherSharedNamespaceClass.vb +++ b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/ConsoleApp2/AnotherSharedNamespaceClass.vb @@ -1,3 +1,4 @@ + Namespace NamespaceSharedWithOtherAssembly Friend Class AnotherSharedNamespaceClass End Class diff --git a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/ConsoleApp2/Properties/AssemblyInfo.vb b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/ConsoleApp2/Properties/AssemblyInfo.vb index a6d1d0a6b..971b5e0bd 100644 --- a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/ConsoleApp2/Properties/AssemblyInfo.vb +++ b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/ConsoleApp2/Properties/AssemblyInfo.vb @@ -1,7 +1,6 @@ Imports System.Reflection Imports System.Runtime.InteropServices - ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. diff --git a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/NetCore/YetAnotherSharedNamespaceClass.vb b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/NetCore/YetAnotherSharedNamespaceClass.vb index 7c399e546..4b03997e0 100644 --- a/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/NetCore/YetAnotherSharedNamespaceClass.vb +++ b/Tests/TestData/MultiFileCharacterization/CSToVBResults/ConvertWholeSolution/NetCore/YetAnotherSharedNamespaceClass.vb @@ -1,3 +1,4 @@ + Namespace NamespaceSharedWithOtherAssembly Friend Class YetAnotherSharedNamespaceClass End Class diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.1.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.1.Designer.cs index 91e3044a2..0ae6f2188 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.1.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.1.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; using System.Diagnostics; @@ -469,4 +471,4 @@ Private ReadOnly m_Context As New Global.Microsoft.VisualBasic.MyServices.Intern } /* TODO ERROR: Skipped EndIfDirectiveTrivia #End If -*/ +*/ \ No newline at end of file diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.2.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.2.Designer.cs index 993e5af6b..c83bd9fef 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.2.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.2.Designer.cs @@ -6,7 +6,9 @@ using System.Xml.Linq; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. // See Compiler::LoadXmlSolutionExtension namespace VbLibrary.My diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.3.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.3.Designer.cs index 7890c547e..75d58675f 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.3.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertVbLibraryOnly/VbLibrary/My Project/MyNamespace.Static.3.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.1.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.1.Designer.cs index 6d71597e1..8b5808adc 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.1.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.1.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; using System.Diagnostics; @@ -469,4 +471,4 @@ Private ReadOnly m_Context As New Global.Microsoft.VisualBasic.MyServices.Intern } /* TODO ERROR: Skipped EndIfDirectiveTrivia #End If -*/ +*/ \ No newline at end of file diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.2.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.2.Designer.cs index 76ebf2333..1024d0149 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.2.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.2.Designer.cs @@ -6,7 +6,9 @@ using System.Xml.Linq; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. // See Compiler::LoadXmlSolutionExtension namespace ConsoleApp1.My diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.3.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.3.Designer.cs index 7890c547e..75d58675f 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.3.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp1/My Project/MyNamespace.Static.3.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.1.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.1.Designer.cs index c7b242523..8536d4615 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.1.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.1.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. /* TODO ERROR: Skipped IfDirectiveTrivia diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.2.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.2.Designer.cs index 476dd2115..7f03a525a 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.2.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.2.Designer.cs @@ -5,7 +5,9 @@ using System.Xml.Linq; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. // See Compiler::LoadXmlSolutionExtension namespace ConsoleApp4.My diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.3.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.3.Designer.cs index 7890c547e..75d58675f 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.3.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/ConsoleApp4/My Project/MyNamespace.Static.3.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.1.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.1.Designer.cs index eb374c4db..7321c4312 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.1.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.1.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; using System.Diagnostics; @@ -468,4 +470,4 @@ public ThreadSafeObjectProvider() : base() } /* TODO ERROR: Skipped EndIfDirectiveTrivia #End If -*/ +*/ \ No newline at end of file diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.2.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.2.Designer.cs index 61a72dac9..5400a9c3a 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.2.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.2.Designer.cs @@ -6,7 +6,9 @@ using System.Xml.Linq; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. // See Compiler::LoadXmlSolutionExtension namespace Prefix.VbLibrary.My diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.3.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.3.Designer.cs index 7890c547e..75d58675f 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.3.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/Prefix.VbLibrary/My Project/MyNamespace.Static.3.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.1.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.1.Designer.cs index 91e3044a2..0ae6f2188 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.1.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.1.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; using System.Diagnostics; @@ -469,4 +471,4 @@ Private ReadOnly m_Context As New Global.Microsoft.VisualBasic.MyServices.Intern } /* TODO ERROR: Skipped EndIfDirectiveTrivia #End If -*/ +*/ \ No newline at end of file diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.2.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.2.Designer.cs index 993e5af6b..c83bd9fef 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.2.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.2.Designer.cs @@ -6,7 +6,9 @@ using System.Xml.Linq; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. // See Compiler::LoadXmlSolutionExtension namespace VbLibrary.My diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.3.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.3.Designer.cs index 7890c547e..75d58675f 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.3.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbLibrary/My Project/MyNamespace.Static.3.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/AnInterfaceImplementation.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/AnInterfaceImplementation.cs index d03258779..99ec25a42 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/AnInterfaceImplementation.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/AnInterfaceImplementation.cs @@ -11,10 +11,7 @@ public string APropertyWithDifferentName } } - string AnInterface.AnInterfaceProperty - { - get => APropertyWithDifferentName; - } + string AnInterface.AnInterfaceProperty { get => APropertyWithDifferentName; } public void AMethodWithDifferentName() { diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.1.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.1.Designer.cs index 7890c547e..75d58675f 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.1.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.1.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.2.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.2.Designer.cs index 18db7e480..0ffe3aa03 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.2.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.2.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; using System.Diagnostics; @@ -1303,7 +1305,7 @@ public static double ToDouble(object Value) } else if (Value is float) { - return (float)Value; + return (double)(float)Value; } else if (Value is double) { diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.3.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.3.Designer.cs index 669a39c2c..3f1a54eaf 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.3.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/VbNetStandardLib/My Project/MyNamespace.Static.3.Designer.cs @@ -5,7 +5,9 @@ using System.Xml.Linq; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. // See Compiler::LoadXmlSolutionExtension namespace VbNetStandardLib.My diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.1.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.1.Designer.cs index 13411ebda..43b0d752e 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.1.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.1.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; using System.Collections; @@ -511,4 +513,4 @@ Private ReadOnly m_Context As New Global.Microsoft.VisualBasic.MyServices.Intern } /* TODO ERROR: Skipped EndIfDirectiveTrivia #End If -*/ +*/ \ No newline at end of file diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.2.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.2.Designer.cs index d9ecdde87..69cfad93b 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.2.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.2.Designer.cs @@ -6,7 +6,9 @@ using System.Xml.Linq; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. // See Compiler::LoadXmlSolutionExtension namespace WindowsAppVb.My diff --git a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.3.Designer.cs b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.3.Designer.cs index 7890c547e..75d58675f 100644 --- a/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.3.Designer.cs +++ b/Tests/TestData/MultiFileCharacterization/VBToCSResults/ConvertWholeSolution/WindowsAppVb/My Project/MyNamespace.Static.3.Designer.cs @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. using System; diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 72940d918..eb4a39f06 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -26,8 +26,11 @@ - - + + + + + diff --git a/Tests/VB/ExpressionTests.cs b/Tests/VB/ExpressionTests.cs index 44c5b1e0e..9ac894d1e 100644 --- a/Tests/VB/ExpressionTests.cs +++ b/Tests/VB/ExpressionTests.cs @@ -46,7 +46,8 @@ public string StringInter(string t, DateTime dt) } } }", - @"Namespace Global.InnerNamespace + @" +Namespace Global.InnerNamespace Public Class Test Public Function StringInter(ByVal t As String, ByVal dt As Date) As String Dim a = $""pre{t} t"" @@ -75,9 +76,10 @@ public string InterStringDateFormat(DateTime dt) string a = $""Soak: {dt: d\\.h\\:mm\\:ss\\.f}""; return a; } -}", @"Public Class Test +}", @" +Public Class Test Public Function InterStringDateFormat(ByVal dt As Date) As String - Dim a As String = $""Soak: {dt: d\.h\:mm\:ss\.f}"" + Dim a = $""Soak: {dt: d\.h\:mm\:ss\.f}"" Return a End Function End Class" @@ -95,7 +97,7 @@ void TestMethod(string str) } }", @"Friend Class TestClass Private Sub TestMethod(ByVal str As String) - Dim result As Boolean = If(Equals(str, """"), True, False) + Dim result = If(Equals(str, """"), True, False) End Sub End Class"); } @@ -168,7 +170,7 @@ public int DoFunc(System.Func func) { Public Sub TestMethod(ByVal b As Integer) Dim a As Integer DoAction(Sub() a = b) - Dim c As Integer = Me.DoFunc(Function() CSharpImpl.__Assign(a, b)) + Dim c = Me.DoFunc(Function() CSharpImpl.__Assign(a, b)) End Sub Public Sub DoAction(ByVal action As Action) @@ -454,7 +456,7 @@ public static void Main() } }", @"Public Class Test Public Shared Sub Main() - Dim y As Integer = 1 + Dim y = 1 y <<= 1 y >>= 1 y = y << 1 @@ -476,7 +478,7 @@ void TestMethod() { }", @"Public Class TestClass Private Sub TestMethod() - Dim x As Integer = 10 + Dim x = 10 x *= 3 x /= 3 End Sub @@ -497,7 +499,7 @@ void TestMethod(string str) } }", @"Friend Class TestClass Private Sub TestMethod(ByVal str As String) - Dim length As Integer = If(str?.Length, -1) + Dim length = If(str?.Length, -1) Console.WriteLine(length) Console.ReadKey() Dim redirectUri As String = context.OwinContext.Authentication?.AuthenticationResponseChallenge?.Properties?.RedirectUri @@ -709,7 +711,7 @@ End Module public async Task CreateValueTupleTypeAsync() { await TestConversionCSharpToVisualBasicAsync(@"(double Sum, int Count) t2 = (4.5, 3);", - @"Dim t2 As (Double, Integer) = (4.5, 3)" + @"Dim t2 = (4.5, 3)" ); } @@ -862,7 +864,7 @@ where n > 5 Console.WriteLine(n); }", @"Private Shared Sub SimpleQuery() - Dim numbers As Integer() = {7, 9, 5, 3, 6} + Dim numbers = {7, 9, 5, 3, 6} Dim res = From n In numbers Where n > 5 Select n For Each n In res @@ -896,7 +898,7 @@ group n by n % 5 into g } }", @"Public Shared Sub Linq40() - Dim numbers As Integer() = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0} + Dim numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0} Dim numberGroups = From n In numbers Group n By __groupByKey1__ = n Mod 5 Into g = Group Select New With { .Remainder = __groupByKey1__, .Numbers = g @@ -952,7 +954,7 @@ End Class Friend Class Test Public Sub Linq102() - Dim categories As String() = New String() {""Beverages"", ""Condiments"", ""Vegetables"", ""Dairy Products"", ""Seafood""} + Dim categories = New String() {""Beverages"", ""Condiments"", ""Vegetables"", ""Dairy Products"", ""Seafood""} Dim products As Product() = GetProductList() Dim q = From c In categories Join p In products On c Equals p.Category Select New With { .Category = c, p.ProductName @@ -966,7 +968,7 @@ End Class 3 source compilation errors: CS0103: The name 'GetProductList' does not exist in the current context -CS1935: Could not find an implementation of the query pattern for source type 'string[]'. 'Join' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'? +CS1935: Could not find an implementation of the query pattern for source type 'string[]'. 'Join' not found. Are you missing required assembly references or a using directive for 'System.Linq'? CS0103: The name 'Console' does not exist in the current context 1 target compilation errors: BC30451: 'GetProductList' is not declared. It may be inaccessible due to its protection level."); @@ -1003,7 +1005,7 @@ join p in products on c equals p.Category into ps } } }", @"Public Sub Linq103() - Dim categories As String() = New String() {""Beverages"", ""Condiments"", ""Vegetables"", ""Dairy Products"", ""Seafood""} + Dim categories = New String() {""Beverages"", ""Condiments"", ""Vegetables"", ""Dairy Products"", ""Seafood""} Dim products = GetProductList() Dim q = From c In categories Group Join p In products On c Equals p.Category Into ps = Group Select New With { .Category = c, @@ -1084,7 +1086,7 @@ End If End Function Public Sub New() - Dim str As String = create(Me) + Dim str = create(Me) End Sub End Class"); } @@ -1187,7 +1189,7 @@ public void Example(DateTime?[] values) { Public Class Class1 Public Sub Example(ByVal values As Date?()) - Dim nullableDate As Date? = values.SingleOrDefault(Function(x) x IsNot Nothing) + Dim nullableDate = values.SingleOrDefault(Function(x) x IsNot Nothing) End Sub End Class", hasLineCommentConversionIssue: true); } @@ -1227,10 +1229,10 @@ public void DoSomething() { } }", @"Public Class TestClass Public Sub New() - Dim i As Integer = 0 - Dim j As Integer = 0 - Dim s1 As String = ""string1"" - Dim s2 As String = ""string2"" + Dim i = 0 + Dim j = 0 + Dim s1 = ""string1"" + Dim s2 = ""string2"" Dim object1 As Object = s1 Dim object2 As Object = s2 If i = j Then DoSomething() diff --git a/Tests/VB/MemberTests.cs b/Tests/VB/MemberTests.cs index 54215a7f6..dc021c324 100644 --- a/Tests/VB/MemberTests.cs +++ b/Tests/VB/MemberTests.cs @@ -754,7 +754,7 @@ public int Test { }", @"Public Partial Class HasConflictingPropertyAndField Public Function HasConflictingParam(ByVal test As Integer) As Integer - Dim lTEST As Integer = 0 + Dim lTEST = 0 testField = test + lTEST Return test End Function @@ -765,7 +765,7 @@ Private testField As Integer Public Property Test As Integer Get - Dim lTEST As Integer = 0 + Dim lTEST = 0 Return testField + lTEST End Get Set(ByVal value As Integer) @@ -1402,7 +1402,8 @@ public override void TestMethod(T parameter) where T : class { } }", - @"Public Class BaseClass + @" +Public Class BaseClass Public Overridable Sub TestMethod(Of T As Class)(ByVal parameter As T) End Sub End Class @@ -1422,7 +1423,8 @@ await TestConversionCSharpToVisualBasicAsync( class TestClass { private DateTime date; }", - @"Friend Class TestClass + @" +Friend Class TestClass Private [date] As Date End Class"); } diff --git a/Tests/VB/NamespaceLevelTests.cs b/Tests/VB/NamespaceLevelTests.cs index 396d7e2eb..8ac7c8af7 100644 --- a/Tests/VB/NamespaceLevelTests.cs +++ b/Tests/VB/NamespaceLevelTests.cs @@ -305,6 +305,7 @@ public class TestClass { } }", @"Imports System.Collections ' Moves outside namespace + Namespace System Public Class TestClass Public Property [Property] As Hashtable diff --git a/Tests/VB/SpecialConversionTests.cs b/Tests/VB/SpecialConversionTests.cs index 2d548c867..cb5b89731 100644 --- a/Tests/VB/SpecialConversionTests.cs +++ b/Tests/VB/SpecialConversionTests.cs @@ -118,7 +118,7 @@ void TestMethod() }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer, a As Integer = 5 + Dim b As Integer, a = 5 b = System.Math.Min(System.Threading.Interlocked.Increment(a), a - 1) End Sub End Class", conversionOptions: EmptyNamespaceOptionStrictOff); @@ -388,7 +388,6 @@ void TestMethod() }", @"Friend Class TestClass Private Sub TestMethod() If Tiles IsNot Nothing Then - For Each t As Tile In Tiles Me.TileTray.Controls.Remove(t) Next @@ -509,7 +508,7 @@ await TestConversionCSharpToVisualBasicAsync( }", @"Private Sub Test() Dim lAB As Object = 5 - Dim Ab As Integer = CInt(o) + Dim Ab = CInt(o) End Sub 1 source compilation errors: @@ -526,7 +525,7 @@ await TestConversionCSharpToVisualBasicAsync( }", @"Private Sub Test() Dim lTest1 As Object = 5 - Dim lTesT As Integer = CInt(o) + Dim lTesT = CInt(o) End Sub 1 source compilation errors: @@ -547,7 +546,7 @@ await TestConversionCSharpToVisualBasicAsync( @"Public ReadOnly Property Test As Integer Get Dim lTest1 As Object = 5 - Dim lTesT As Integer = CInt(o) + Dim lTesT = CInt(o) Return lTest1 End Get End Property @@ -584,12 +583,12 @@ Private testField As EventHandler Public Custom Event Test As EventHandler AddHandler(ByVal value As EventHandler) Dim lTeSt1 As Object = 5 - Dim lTesT As Integer = CInt(o) + Dim lTesT = CInt(o) testField = [Delegate].Combine(testField, value) End AddHandler RemoveHandler(ByVal value As EventHandler) Dim lTeSt1 As Object = 5 - Dim lTesT As Integer = CInt(o) + Dim lTesT = CInt(o) testField = [Delegate].Remove(testField, value) End RemoveHandler RaiseEvent(ByVal sender As Object, ByVal e As EventArgs) @@ -748,8 +747,8 @@ public void Method() { }", @"Public Class TestClass Public Sub Method() - Dim vbLf As String = Microsoft.VisualBasic.vbLf - Dim vbCrLf As String = Microsoft.VisualBasic.vbCrLf + Dim vbLf = Microsoft.VisualBasic.vbLf + Dim vbCrLf = Microsoft.VisualBasic.vbCrLf End Sub End Class", conversionOptions: EmptyNamespaceOptionStrictOff); } diff --git a/Tests/VB/StandaloneStatementTests.cs b/Tests/VB/StandaloneStatementTests.cs index fc6217304..0e42bcf55 100644 --- a/Tests/VB/StandaloneStatementTests.cs +++ b/Tests/VB/StandaloneStatementTests.cs @@ -12,7 +12,7 @@ public async Task ReassignmentAsync() await TestConversionCSharpToVisualBasicAsync( @"int num = 4; num = 5;", - @"Dim num As Integer = 4 + @"Dim num = 4 num = 5", expectSurroundingMethodBlock: true); } diff --git a/Tests/VB/StatementTests.cs b/Tests/VB/StatementTests.cs index c4e615873..806aff415 100644 --- a/Tests/VB/StatementTests.cs +++ b/Tests/VB/StatementTests.cs @@ -131,7 +131,7 @@ void TestMethod() } }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer = 0 + Dim b = 0 End Sub End Class"); } @@ -238,7 +238,7 @@ void TestMethod() } }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer() = {1, 2, 3} + Dim b = {1, 2, 3} End Sub End Class"); } @@ -273,7 +273,7 @@ void TestMethod() } }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer() = New Integer() {1, 2, 3} + Dim b = New Integer() {1, 2, 3} End Sub End Class"); } @@ -289,7 +289,7 @@ void TestMethod() } }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer() = New Integer(2) {1, 2, 3} + Dim b = New Integer(2) {1, 2, 3} End Sub End Class"); } @@ -324,7 +324,7 @@ void TestMethod() } }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer(,) = { + Dim b = { {1, 2}, {3, 4}} End Sub @@ -345,7 +345,7 @@ void TestMethod() } }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer(,) = New Integer(,) { + Dim b = New Integer(,) { {1, 2}, {3, 4}} End Sub @@ -366,7 +366,7 @@ void TestMethod() } }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer(,) = New Integer(1, 1) { + Dim b = New Integer(1, 1) { {1, 2}, {3, 4}} End Sub @@ -403,7 +403,7 @@ void TestMethod() } }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer()() = {New Integer() {1, 2}, New Integer() {3, 4}} + Dim b = {New Integer() {1, 2}, New Integer() {3, 4}} End Sub End Class"); } @@ -419,7 +419,7 @@ void TestMethod() } }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer()() = New Integer()() {New Integer() {1, 2}, New Integer() {3, 4}} + Dim b = New Integer()() {New Integer() {1, 2}, New Integer() {3, 4}} End Sub End Class"); } @@ -435,7 +435,7 @@ void TestMethod() } }", @"Friend Class TestClass Private Sub TestMethod() - Dim b As Integer()() = New Integer(1)() {New Integer() {1, 2}, New Integer() {3, 4}} + Dim b = New Integer(1)() {New Integer() {1, 2}, New Integer() {3, 4}} End Sub End Class"); } @@ -456,8 +456,8 @@ void TestMethod() }", @"Friend Class Test Private Sub TestMethod() the_beginning: - Dim value As Integer = 1 - Const myPIe As Double = Math.PI + Dim value = 1 + Const myPIe = Math.PI Dim text = ""This is my text!"" GoTo the_beginning End Sub @@ -676,7 +676,7 @@ void TestMethod(int[] values) } }", @"Friend Class TestClass Private Sub TestMethod(ByVal values As Integer()) - For Each val As Integer In values + For Each val In values If val = 2 Then Continue For If val = 3 Then Exit For Next @@ -817,7 +817,7 @@ void TestMethod(int[] b, int[] s, int nbMessage) } }", @"Friend Class TestClass Private Sub TestMethod(ByVal b As Integer(), ByVal s As Integer(), ByVal nbMessage As Integer) - For m As Integer = nbMessage To 1 Step -1 + For m = nbMessage To 1 Step -1 ' Loop body Next End Sub @@ -896,9 +896,9 @@ void TestMethod() { }", @"Friend Class TestClass Private Sub TestMethod() - Dim summary As Integer = 0 + Dim summary = 0 - For month As Integer = 1 To 12 + For month = 1 To 12 summary += month Next End Sub @@ -957,7 +957,7 @@ void TestMethod(IEnumerable counts) { }", @"Friend Class TestClass Private Sub TestMethod(ByVal counts As IEnumerable(Of Integer)) - Dim summary As Integer = 0 + Dim summary = 0 Dim action As Action = Sub() For Each c In counts Dim current = c @@ -1054,13 +1054,13 @@ static void Main() } }", @"Friend Class GotoTest1 Private Shared Sub Main() - Dim x As Integer = 200, y As Integer = 4 - Dim count As Integer = 0 - Dim array As String(,) = New String(x - 1, y - 1) {} + Dim x = 200, y = 4 + Dim count = 0 + Dim array = New String(x - 1, y - 1) {} - For i As Integer = 0 To x - 1 + For i = 0 To x - 1 - For j As Integer = 0 To y - 1 + For j = 0 To y - 1 array(i, j) = Threading.Interlocked.Increment(count).ToString() Next Next @@ -1068,9 +1068,9 @@ Dim array As String(,) = New String(x - 1, y - 1) {} Console.Write(""Enter the number to search for: "") Dim myNumber As String = Console.ReadLine() - For i As Integer = 0 To x - 1 + For i = 0 To x - 1 - For j As Integer = 0 To y - 1 + For j = 0 To y - 1 If array(i, j).Equals(myNumber) Then GoTo Found @@ -1397,7 +1397,7 @@ Friend Class TestClass Private Iterator Function TestMethod(ByVal number As Integer) As IEnumerable(Of Integer) If number < 0 Then Return - For i As Integer = 0 To number - 1 + For i = 0 To number - 1 Yield i Next End Function diff --git a/Tests/VB/TriviaTests.cs b/Tests/VB/TriviaTests.cs index 5b2a0c466..de16b5fde 100644 --- a/Tests/VB/TriviaTests.cs +++ b/Tests/VB/TriviaTests.cs @@ -50,7 +50,6 @@ class CommentTestClass //Don't rename Imports System.Diagnostics 'Using statement Imports System.Runtime.InteropServices - 'blank line Namespace ANamespace 'namespace @@ -76,6 +75,7 @@ If argument IsNot Nothing Then 'never Debug.WriteLine(1) ' Check debug window Debug.WriteLine(2) End If 'argument1 != null + argument3 = Nothing '3 #Else 'ElseDirective keeps comments argument = new object(); diff --git a/Tests/VB/TypeCastTests.cs b/Tests/VB/TypeCastTests.cs index e41fe4bb6..2186d2dba 100644 --- a/Tests/VB/TypeCastTests.cs +++ b/Tests/VB/TypeCastTests.cs @@ -34,7 +34,7 @@ await TestConversionCSharpToVisualBasicAsync( string s = (string) o; }", @"Private Sub Test() Dim o As Object = ""Test"" - Dim s As String = CStr(o) + Dim s = CStr(o) End Sub"); } @@ -48,7 +48,7 @@ await TestConversionCSharpToVisualBasicAsync( System.Collections.Generic.List l = (System.Collections.Generic.List) o; }", @"Private Sub Test() Dim o As Object = New List(Of Integer)() - Dim l As List(Of Integer) = CType(o, List(Of Integer)) + Dim l = CType(o, List(Of Integer)) End Sub"); } @@ -137,7 +137,7 @@ await TestConversionCSharpToVisualBasicAsync( char CR = (char)0xD; }", @"Private Sub Test() - Dim CR As Char = Microsoft.VisualBasic.ChrW(&HD) + Dim CR = Microsoft.VisualBasic.ChrW(&HD) End Sub", conversionOptions: EmptyNamespaceOptionStrictOff); } [Fact] diff --git a/Vsix/AssemblyInfo.cs b/Vsix/AssemblyInfo.cs deleted file mode 100644 index 293b33223..000000000 --- a/Vsix/AssemblyInfo.cs +++ /dev/null @@ -1,6 +0,0 @@ -using Microsoft.VisualStudio.Shell; - -[assembly: ProvideCodeBase(AssemblyName = "Microsoft.Bcl.AsyncInterfaces", Version = "1.0.0.0", PublicKeyToken = "cc7b13ffcd2ddd51", CodeBase = "$PackageFolder$\\Lib\\Microsoft.Bcl.AsyncInterfaces.dll")] -[assembly: ProvideCodeBase(AssemblyName = "System.Runtime.CompilerServices.Unsafe", Version = "4.0.4.1", PublicKeyToken = "b03f5f7f11d50a3a", CodeBase = "$PackageFolder$\\Lib\\System.Runtime.CompilerServices.Unsafe.dll")] -[assembly: ProvideCodeBase(AssemblyName = "System.Threading.Tasks.Dataflow", Version = "4.6.0.0", PublicKeyToken = "b03f5f7f11d50a3a", CodeBase = "$PackageFolder$\\Lib\\System.Threading.Tasks.Dataflow.dll")] -[assembly: ProvideBindingRedirection(AssemblyName = "System.Threading.Tasks.Extensions", OldVersionLowerBound = "4.0.0.0", OldVersionUpperBound = "4.2.0.0", NewVersion = "4.2.0.1", PublicKeyToken = "cc7b13ffcd2ddd51", CodeBase = "$PackageFolder$\\Lib\\System.Threading.Tasks.Extensions.dll")] diff --git a/Vsix/CodeConversion.cs b/Vsix/CodeConversion.cs index c4889cc30..b7ac11d7d 100644 --- a/Vsix/CodeConversion.cs +++ b/Vsix/CodeConversion.cs @@ -57,7 +57,7 @@ public CodeConversion(IAsyncServiceProvider serviceProvider, try { await EnsureBuiltAsync(selectedProjects); await _joinableTaskFactory.RunAsync(async () => { - var convertedFiles = ConvertProjectUnhandled(selectedProjects, cancellationToken); + var convertedFiles = ConvertProjectUnhandledAsync(selectedProjects, cancellationToken); await WriteConvertedFilesAndShowSummaryAsync(convertedFiles); }); } catch (OperationCanceledException) { @@ -73,7 +73,7 @@ await _joinableTaskFactory.RunAsync(async () => { var containingProject = await VisualStudioInteraction.GetFirstProjectContainingAsync(documentsFilePath.First()); await EnsureBuiltAsync(containingProject is null ? Array.Empty() : new[]{containingProject}); await _joinableTaskFactory.RunAsync(async () => { - var result = ConvertDocumentsUnhandled(documentsFilePath, cancellationToken); + var result = ConvertDocumentsUnhandledAsync(documentsFilePath, cancellationToken); await WriteConvertedFilesAndShowSummaryAsync(result); }); } catch (OperationCanceledException) { @@ -260,7 +260,7 @@ private async Task GetConversionSummaryAsync(IReadOnlyCollection return await ProjectConversion.ConvertSingleAsync(document, new SingleConversionOptions {SelectedTextSpan = selectedTextSpan, AbandonOptionalTasksAfter = await GetAbandonOptionalTasksAfterAsync()}, CreateOutputWindowProgress(), cancellationToken); } - private async IAsyncEnumerable ConvertDocumentsUnhandled( + private async IAsyncEnumerable ConvertDocumentsUnhandledAsync( IReadOnlyCollection documentsPath, [EnumeratorCancellation] CancellationToken cancellationToken) where TLanguageConversion : ILanguageConversion, new() { @@ -297,7 +297,7 @@ private async Task ConvertFileTextAsync(s return convertTextOnly; } - private async IAsyncEnumerable ConvertProjectUnhandled(IReadOnlyCollection selectedProjects, [EnumeratorCancellation] CancellationToken cancellationToken) + private async IAsyncEnumerable ConvertProjectUnhandledAsync(IReadOnlyCollection selectedProjects, [EnumeratorCancellation] CancellationToken cancellationToken) where TLanguageConversion : ILanguageConversion, new() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); @@ -315,7 +315,7 @@ private async IAsyncEnumerable ConvertProjectUnhandled(projects, conversionOptions: conversionOptions, progress: CreateOutputWindowProgress(), cancellationToken: cancellationToken); - await foreach (var result in solutionConverter.Convert()) yield return result; + await foreach (var result in solutionConverter.ConvertAsync()) yield return result; } private async Task GetAbandonOptionalTasksAfterAsync() => TimeSpan.FromMinutes((await GetOptions()).FormattingTimeout); diff --git a/Vsix/Vsix.csproj b/Vsix/Vsix.csproj index fe3300fd4..d5ab61f19 100644 --- a/Vsix/Vsix.csproj +++ b/Vsix/Vsix.csproj @@ -51,16 +51,15 @@ - - + + + compile; build; native; contentfiles; analyzers; buildtransitive + - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - 9.0.1 - 4.3.0 @@ -77,26 +76,6 @@ Menus.ctmenu Designer - - true - Lib\Microsoft.Bcl.AsyncInterfaces.dll - PreserveNewest - - - true - Lib\System.Runtime.CompilerServices.Unsafe.dll - PreserveNewest - - - true - Lib\System.Threading.Tasks.Dataflow.dll - PreserveNewest - - - true - Lib\System.Threading.Tasks.Extensions.dll - PreserveNewest - true PreserveNewest @@ -132,7 +111,6 @@ AppDomainExtensions.cs - diff --git a/Vsix/source.extension.vsixmanifest b/Vsix/source.extension.vsixmanifest index 20d78f681..0eca8de3b 100644 --- a/Vsix/source.extension.vsixmanifest +++ b/Vsix/source.extension.vsixmanifest @@ -13,7 +13,7 @@ code converter vb csharp visual basic csharp net translate - + x86 @@ -21,13 +21,13 @@ - + - + diff --git a/Web/Web.csproj b/Web/Web.csproj index 0ceda3ab9..c6ee14f52 100644 --- a/Web/Web.csproj +++ b/Web/Web.csproj @@ -20,7 +20,7 @@ - +