ant-design-blazor/components/core/HashCodes/HashCodeExtensions.cs
老九 b1bbe30323 perf(module: table): use hash-code comparison for all the parameters to control UI rendering (#716)
* 为组件增加GetParametersHashCode()扩展方法,以支持控制组件的渲染方式;
为Table组件增加RenderMode的渲染模式参数;

* fix: translate the comments

Co-authored-by: ElderJames <shunjiey@hotmail.com>
2020-10-25 18:31:31 +08:00

28 lines
907 B
C#

using Microsoft.AspNetCore.Components;
namespace AntDesign.Core.HashCodes
{
/// <summary>
/// Provide HashCode calculation of component parameters and other functions
/// </summary>
static class HashCodeExtensions
{
/// <summary>
/// Compute the HashCode for all parameters
/// </summary>
/// <typeparam name="TComponent"></typeparam>
/// <param name="component">Component</param>
/// <returns></returns>
public static int GetParametersHashCode<TComponent>(this TComponent component) where TComponent : ComponentBase
{
var hashCode = 0;
var descriptors = ParameterDescriptor<TComponent>.Descriptors;
foreach (var descriptor in descriptors)
{
hashCode ^= descriptor.GetValueHashCode(component);
}
return hashCode;
}
}
}