ant-design-blazor/components/select/internal/DataSourceEqualityComparer.cs
Andrzej Bakun de69cc5dd5 fix(module: select): value no longer reset on datasource set (#1906)
* fix(module:select): value no longer reset on datasource set

* fix(module:select): dataSource change detection

* fix: improve datasource detection
add item & set value in SelectOption

* tests: scenario from issue #1207

* fix: DataSourceEqualityComparer default
2021-09-05 18:13:38 +08:00

31 lines
917 B
C#

using System.Collections.Generic;
namespace AntDesign
{
internal class DataSourceEqualityComparer<TItemValue, TItem> : IEqualityComparer<TItem>
{
private Select<TItemValue, TItem> SelectParent { get; }
public DataSourceEqualityComparer(Select<TItemValue, TItem> selectParent)
{
SelectParent = selectParent;
}
public bool Equals(TItem x, TItem y)
{
if (SelectParent._getLabel is null)
{
return x.ToString().Equals(y.ToString())
&& SelectParent._getValue(x).Equals(SelectParent._getValue(y));
}
return SelectParent._getLabel(x).Equals(SelectParent._getLabel(y))
&& SelectParent._getValue(x).Equals(SelectParent._getValue(y));
}
public int GetHashCode(TItem obj)
{
return obj.GetHashCode();
}
}
}