/// <summary> /// 检测是否某一项改变 /// </summary> /// <param name="hashModel"></param> /// <param name="key"></param> /// <returns></returns> public static bool CheckChanged(this IHashDictionary hashModel, string key) { if (hashModel == null || key == null) { return(false); } var hashValues = hashModel.GetHashValues(); if (!hashValues.ContainsKey(key)) { return(false); } var hashValue = hashValues[key]; var properties = hashModel.GetProperties(); if (!properties.ContainsKey(key)) { //be removed! return(true); } var sameHash = properties[key].VerifyObjectHash(hashValue.Hash); if (!sameHash) { //hash不一样,一定变化 return(true); } //哈希值虽然一样,但只要不是初始版本的,都视为变化(新增) var initVersion = hashModel.GetVersions().LastOrDefault(); return(initVersion != hashValue.Version); }
/// <summary> /// 检测是否有任何项改变 /// </summary> /// <param name="hashModel"></param> /// <returns></returns> public static bool CheckAnyChanged(this IHashDictionary hashModel) { if (hashModel == null) { return(false); } var hashValues = hashModel.GetHashValues(); foreach (var hashValue in hashValues) { var changedForKey = CheckChanged(hashModel, hashValue.Key); if (changedForKey) { return(true); } } return(false); }