ant-design-blazor/components/core/Extensions/ParameterViewExtensions.cs
pankey888 b977e4e3ca
refactor(module: tree): Refactor tree's Selected/Checked/Expanded parameters (#3896)
* refactor(module: tree): Refactor tree's Selected/Checked/Expanded parameters.(#2112,#2577,#2754,#2848,#3238,#3641,#3730,#3845,#3881,#3890,#3891,#3892)

* Update the demo & document of tree & tree-select.

* refactor(module: tree): Remove IsSelected/IsChecked/IsExpanded.
2024-06-05 00:26:31 +08:00

51 lines
1.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.AspNetCore.Components
{
public static class ParameterViewExtensions
{
public static bool IsParameterChanged<T>(this ParameterView parameters,
string parameterName, T value)
{
return IsParameterChanged(parameters, parameterName, value, out _);
}
public static bool IsParameterChanged<T>(this ParameterView parameters,
string parameterName, T value, out T newValue)
{
if (parameters.TryGetValue(parameterName, out newValue))
{
if (newValue == null && value == null)
{
return false;
}
if (newValue == null && value != null)
{
return true;
}
if (newValue != null && value == null)
{
return true;
}
if (newValue is string[] stringNewValue && value is string[] stringValue)
{
return !stringNewValue.SequenceEqual(stringValue);
}
if (!EqualityComparer<T>.Default.Equals(value, newValue))
{
return true;
}
}
return false;
}
}
}