Skip to content

Improvements to 'LINQ query to foreach' #25639

@ivanbasov

Description

@ivanbasov

This issue will handle improvements to the original PR: #25362 that should be covered later:

  • Support single and multiline comments in QueryExpressions.
  • Support LINQ queries in tuples
  • Consider using SyntaxEditor/SyntaxGenerator instead of SyntaxFactory. Benefit: use in both VB and C# (if we can reuse this in algorithms)
  • replace hardcoding 'var' with user preferred.
  • reuse variable name generation from Add a refactoring to convert a common for-loop form to a foreach-statement. #25469
  • split checking and building algorithms by using the visitor pattern
  • Add test for from x in XX where XX is not IEnumerable, i.e. requires AsEnumerable.
  • Consider to be more defensive or the opposite convert always but provide warnings, check bail outs for each clause
  • Make check for name of "Func" using var funcSymbol = semanticModel.Compilation.GetTypeByMetadataName(typeof(...).FullName)
  • Add support for All, Any, FirstOrDefault and other IEnumerable extensions
  • Consider the following approach for clauses validation: if it is a standard Linq - do not show a warning, otherwise - show a warning
  • Consider creating block bodies if the query expression is under ArrowExpressionClause, i.e. lambdas by adding bodies instead of expression bodies
  • checks for if (_semanticModel.GetTypeInfo(selectClause.Expression).Type.ContainsAnonymousType()) seem to be too conservative. Consider revisit them.
  • Consider support of IQueryable
  • Consider making returnedType.OriginalDefinition?.SpecialType == SpecialType.System_Collections_Generic_IEnumerable_T weaker
  • consider why we could not use SymbolEquivalenceComparer.Instance.Equals for copmaring types. It returns true for SomeType vs int having conversion to each other.
  • Support query expressions in foreach variable statements, like foreach(var (a,b) in query)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions