/// <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 Equals(ITypeSymbol x, ITypeSymbol y) { if (ReferenceEquals(x, y)) { return(true); } if (x is null || y is null) { return(false); } if (x.TypeKind != y.TypeKind) { return(false); } if (x is INamedTypeSymbol xNamedType && y is INamedTypeSymbol yNamedType) { return(NamedTypeSymbolComparer.Equals(xNamedType, yNamedType)); } if (x.TypeKind == TypeKind.TypeParameter) { return(x.MetadataName == y.MetadataName && SymbolComparer.Equals(x.ContainingSymbol, y.ContainingSymbol)); } return(x.MetadataName == y.MetadataName && Equals(x.ContainingType, y.ContainingType) && NamespaceSymbolComparer.Equals(x.ContainingNamespace, y.ContainingNamespace)); }
/// <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 Equals(IParameterSymbol x, IParameterSymbol y) { if (ReferenceEquals(x, y)) { return(true); } if (x is null || y is null) { return(false); } return(x.MetadataName == y.MetadataName && SymbolComparer.Equals(x.ContainingSymbol, y.ContainingSymbol)); }
public static bool IsSameType(this ITypeSymbol x, ITypeSymbol y) { if (Equals(x, y)) { return(true); } if (x is null || y is null) { return(false); } if (x is ITypeParameterSymbol xtp) { if (y is ITypeParameterSymbol ytp) { return(xtp.MetadataName == ytp.MetadataName && SymbolComparer.Equals(xtp.ContainingSymbol, ytp.ContainingSymbol)); } foreach (var constraintType in xtp.ConstraintTypes) { if (Is(constraintType, y)) { return(true); } } return(false); } else if (y is ITypeParameterSymbol ytp) { foreach (var constraintType in ytp.ConstraintTypes) { if (Is(x, constraintType)) { return(true); } } return(false); } return(x is INamedTypeSymbol firstNamed && y is INamedTypeSymbol otherNamed && IsSameType(firstNamed, otherNamed)); }