/// <summary> Determines equality by delegating to other compare. </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(ISymbol?x, ISymbol?y) { if (ReferenceEquals(x, y)) { return(true); } if (x is null || y is null || x.Kind != y.Kind || x.MetadataName != y.MetadataName) { return(false); } return((x.Kind, y.Kind) switch { (SymbolKind.Field, SymbolKind.Field) => FieldSymbolComparer.Equal((IFieldSymbol)x, (IFieldSymbol)y), (SymbolKind.Event, SymbolKind.Event) => EventSymbolComparer.Equal((IEventSymbol)x, (IEventSymbol)y), (SymbolKind.Property, SymbolKind.Property) => PropertySymbolComparer.Equal((IPropertySymbol)x, (IPropertySymbol)y), (SymbolKind.Method, SymbolKind.Method) => MethodSymbolComparer.Equal((IMethodSymbol)x, (IMethodSymbol)y), (SymbolKind.Parameter, SymbolKind.Parameter) => ParameterSymbolComparer.Equal((IParameterSymbol)x, (IParameterSymbol)y), (SymbolKind.Local, SymbolKind.Local) => LocalSymbolComparer.Equal((ILocalSymbol)x, (ILocalSymbol)y), (SymbolKind.NamedType, SymbolKind.NamedType) => NamedTypeSymbolComparer.Equal((INamedTypeSymbol)x, (INamedTypeSymbol)y), (SymbolKind.ArrayType, SymbolKind.ArrayType) => TypeSymbolComparer.Equal((ITypeSymbol)x, (ITypeSymbol)y), (SymbolKind.DynamicType, SymbolKind.DynamicType) => TypeSymbolComparer.Equal((ITypeSymbol)x, (ITypeSymbol)y), (SymbolKind.ErrorType, SymbolKind.ErrorType) => false, (SymbolKind.PointerType, SymbolKind.PointerType) => TypeSymbolComparer.Equal((ITypeSymbol)x, (ITypeSymbol)y), (SymbolKind.TypeParameter, SymbolKind.TypeParameter) => TypeSymbolComparer.Equal((ITypeSymbol)x, (ITypeSymbol)y), (SymbolKind.Namespace, SymbolKind.Namespace) => NamespaceSymbolComparer.Equal((INamespaceSymbol)x, (INamespaceSymbol)y), (_, _) => SymbolEqualityComparer.Default.Equals(x, y), });
/// <summary> Determines equality by delegating to other compare. </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(ISymbol x, ISymbol y) { if (ReferenceEquals(x, y)) { return(true); } if (x is null || y is null) { return(false); } if (x is IEventSymbol xEvent && y is IEventSymbol yEvent) { return(EventSymbolComparer.Equals(xEvent, yEvent)); } if (x is IFieldSymbol xField && y is IFieldSymbol yField) { return(FieldSymbolComparer.Equals(xField, yField)); } if (x is ILocalSymbol xLocal && y is ILocalSymbol yLocal) { return(LocalSymbolComparer.Equals(xLocal, yLocal)); } if (x is IMethodSymbol xMethod && y is IMethodSymbol yMethod) { return(MethodSymbolComparer.Equals(xMethod, yMethod)); } if (x is INamedTypeSymbol xNamedType && y is INamedTypeSymbol yNamedType) { return(NamedTypeSymbolComparer.Equals(xNamedType, yNamedType)); } if (x is INamespaceSymbol xNamespace && y is INamespaceSymbol yNamespace) { return(NamespaceSymbolComparer.Equals(xNamespace, yNamespace)); } if (x is IParameterSymbol xParameter && y is IParameterSymbol yParameter) { return(ParameterSymbolComparer.Equals(xParameter, yParameter)); } if (x is IPropertySymbol xProperty && y is IPropertySymbol yProperty) { return(PropertySymbolComparer.Equals(xProperty, yProperty)); } if (x is ITypeSymbol xType && y is ITypeSymbol yType) { return(TypeSymbolComparer.Equals(xType, yType)); } return(x.Equals(y)); }