您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

113 行
3.7 KiB

using System;
using System.Collections.Generic;
namespace UIWidgetsSample
{
public class EquatableUtils
{
// private DeepCollectionEquality _equality = DeepCollectionEquality();
private int mapPropsToHashCode(List<object> props)
{
var value = 0;
foreach (var prop in props)
{
value = _combine(value, prop);
}
return _finish(props == null ? 0 : value);
}
/// Determines whether [list1] and [list2] are equal.
private bool equals(List<object> list1, List<object> list2)
{
if (list1.Equals(list2)) return true;
if (list1 == null || list2 == null) return false;
var length = list1.Count;
if (length != list2.Count) return false;
for (var i = 0; i < length; i++)
{
var unit1 = list1[i];
var unit2 = list2[i];
if (_isEquatable(unit1) && _isEquatable(unit2))
{
if (unit1 != unit2) return false;
}
else if (unit1 is List<object> || unit1 is Dictionary<object, object>)
{
//if (!_equality.equals(unit1, unit2))
if(!Equals(unit1,unit2))
return false;
}
else if (unit1?.GetType() != unit2?.GetType())
{
return false;
}
else if (unit1 != unit2)
{
return false;
}
}
return true;
}
private bool _isEquatable(object _object)
{
return _object is Equatable || _object is EquatableMixin;
}
/// Jenkins Hash Functions
/// https://en.wikipedia.org/wiki/Jenkins_hash_function
private int _combine(int hash, object _object)
{
if (_object is Dictionary<object, object>)
{
var Keys = new List<object>();
foreach (var key in ((Dictionary<object, object>) _object).Keys) Keys.Add(key);
Keys.Sort((a, b) => a.GetHashCode() - b.GetHashCode());
foreach (var key in Keys)
{
var value = (object) null;
var keyValue = ((Dictionary<object, object>) _object).TryGetValue(key, out value);
hash = hash ^ _combine(hash, new Dictionary<object, object> {{key, value}});
}
;
return hash;
}
if (_object is List<object>)
{
foreach (var value in (List<object>) _object) hash = hash ^ _combine(hash, value);
return hash ^ ((List<object>) _object).Count;
}
hash = 0x1fffffff & (hash + _object.GetHashCode());
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
return hash ^ (hash >> 6);
}
private int _finish(int hash)
{
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
hash = hash ^ (hash >> 11);
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}
/// Returns a string for [props].
public static string mapPropsToString(Type runtimeType, List<object> props)
{
var result = "";
var results = new List<string>();
foreach (var prop in props) results.Add(prop.ToString());
//props.map((prop) => prop.toString()).join(', ')
return string.Join(",", results);
}
}
}