/// <summary> Determines equality by name and containing symbol. </summary> /// <param name="x">The first instance.</param> /// <param name="y">The other instance.</param> /// <returns>True if the instances are found equal.</returns> public static bool Equal(ILocalSymbol?x, ILocalSymbol?y) { if (ReferenceEquals(x, y)) { return(true); } if (x is null || y is null) { return(false); } return(x.MetadataName == y.MetadataName && SymbolComparer.Equal(x.ContainingSymbol, y.ContainingSymbol)); }
/// <summary> /// Get a walker with all mutations for <paramref name="fieldOrProperty"/>. /// </summary> /// <param name="fieldOrProperty">The <see cref="FieldOrProperty"/>.</param> /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> /// <returns>A walker with all mutations for <paramref name="fieldOrProperty"/>.</returns> public static MutationWalker For(FieldOrProperty fieldOrProperty, SemanticModel semanticModel, CancellationToken cancellationToken) { if (fieldOrProperty.Symbol.ContainingType.TrySingleDeclaration(cancellationToken, out TypeDeclarationSyntax? typeDeclaration)) { var walker = Borrow(typeDeclaration, SearchScope.Instance, semanticModel, cancellationToken); walker.assignments.RemoveAll(x => !IsFieldOrProperty(x.Left)); walker.prefixUnaries.RemoveAll(x => !IsFieldOrProperty(x.Operand)); walker.postfixUnaries.RemoveAll(x => !IsFieldOrProperty(x.Operand)); walker.refOrOutArguments.RemoveAll(x => !IsFieldOrProperty(x.Expression)); return(walker); } return(Borrow(() => new MutationWalker())); bool IsFieldOrProperty(ExpressionSyntax expression) { return(semanticModel.TryGetSymbol(expression, cancellationToken, out var symbol) && SymbolComparer.Equal(symbol, fieldOrProperty.Symbol)); } }
/// <summary> /// Get a walker with all mutations for <paramref name="localOrParameter"/>. /// </summary> /// <param name="localOrParameter">The <see cref="LocalOrParameter"/>.</param> /// <param name="semanticModel">The <see cref="SemanticModel"/>.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> /// <returns>A walker with all mutations for <paramref name="localOrParameter"/>.</returns> public static MutationWalker For(LocalOrParameter localOrParameter, SemanticModel semanticModel, CancellationToken cancellationToken) { if (localOrParameter.TryGetScope(cancellationToken, out var node)) { var walker = Borrow(node, SearchScope.Member, semanticModel, cancellationToken); walker.assignments.RemoveAll(x => !IsMatch(x.Left)); walker.prefixUnaries.RemoveAll(x => !IsMatch(x.Operand)); walker.postfixUnaries.RemoveAll(x => !IsMatch(x.Operand)); walker.refOrOutArguments.RemoveAll(x => !IsMatch(x.Expression)); return(walker); } return(Borrow(() => new MutationWalker())); bool IsMatch(ExpressionSyntax expression) { return(semanticModel.TryGetSymbol(expression, cancellationToken, out var symbol) && SymbolComparer.Equal(symbol, localOrParameter.Symbol)); } }