private static Variance typedHomogeneousKeyValueEnumerableCompare <T, TSubTypeKey, TSubTypeValue>(T val1, T val2, string fieldName) { var set1 = ((IEnumerable <KeyValuePair <TSubTypeKey, TSubTypeValue> >)val1).ToDictionary(a => a.Key, a => a.Value); var set2 = ((IEnumerable <KeyValuePair <TSubTypeKey, TSubTypeValue> >)val2).ToDictionary(a => a.Key, a => a.Value); return(TExtensions.DictionaryCompare <TSubTypeKey, TSubTypeValue>(set1, set2, fieldName)); }
private static Variance subTypedKeyedTypedHomogeneousObjectEnumerableCompareWithKeyFunc <T, TSubType, TSubTypeKey>(T val1, T val2, string fieldName, Func <TSubType, TSubTypeKey> getKey) { var set1 = ((IEnumerable <TSubType>)val1).ToDictionary(a => getKey(a)); var set2 = ((IEnumerable <TSubType>)val2).ToDictionary(a => getKey(a)); return(TExtensions.DictionaryCompare <TSubTypeKey, TSubType>(set1, set2, fieldName)); }
private static Variance typedHomogeneousObjectEnumerableCompare <T, TSubType>(T val1, T val2, string fieldName) { var idAttribute = typeof(TSubType).GetCustomAttribute <IdPropertyAttribute>(true); return(idAttribute == null ? TExtensions.keyLessTypedHomogeneousObjectEnumerableCompare <T, TSubType>(val1, val2, fieldName) : TExtensions.keyedTypedHomogeneousObjectEnumerableCompare <T, TSubType>(idAttribute, val1, val2, fieldName)); }
public static Variance DetailedCompare <T>(this T val1, T val2, string fieldName) { return(typeof(IEnumerable).IsAssignableFrom(typeof(T)) ? TExtensions.enumerableCompare(val1, val2, fieldName) : typeof(T).IsPrimitive ? TExtensions.valueCompare(val1, val2, fieldName) : TExtensions.objectCompare(val1, val2, fieldName)); }
private void OnChange(IDictionary <string, string> collection, string[] changedKeys) { if (!suppressChange) { try { suppressChange = true; if (collection == UExtensions) { SingletonSubtags["u"] = FormatUExtension(); } else if (collection == TExtensions) { SingletonSubtags["t"] = FormatTExtension(); } else { if (Array.IndexOf(changedKeys, "t") >= 0 || Array.IndexOf(changedKeys, "T") >= 0) { TExtensions.Clear(); if (collection.TryGetValue("t", out string value) && !String.IsNullOrEmpty(value)) { BcpLanguageTag t = BcpLanguageTag.Parse("root-t-" + value); foreach (KeyValuePair <string, string> a in t.TExtensions) { TExtensions.Add(a); } TLang = t.TLang; } else { TLang = ""; } } if (Array.IndexOf(changedKeys, "u") >= 0 || Array.IndexOf(changedKeys, "U") >= 0) { UExtensions.Clear(); Attributes.Clear(); if (collection.TryGetValue("u", out string value) && !String.IsNullOrEmpty(value)) { BcpLanguageTag t = BcpLanguageTag.Parse("root-u-" + value); foreach (KeyValuePair <string, string> a in t.UExtensions) { UExtensions.Add(a); } foreach (string a in t.Attributes) { Attributes.Add(a); } } } } } finally { suppressChange = false; } } }
private static Variance homogeneousEnumerableCompare <T>(T val1, T val2, string fieldName) { var subType = typeof(T).GetGenericArguments()[0]; return(typeof(KeyValuePair <,>).IsAssignableFrom(subType) ? TExtensions.homogeneousKeyValueEnumerableCompare(subType, val1, val2, fieldName) : subType.IsPrimitive ? homogeneousValueEnumerableCompare(subType, val1, val2, fieldName) : homogeneousObjectEnumerableCompare(subType, val1, val2, fieldName)); }
public int SaveSite(SiteDto site) { if (site.SiteId != 0 && _resp.GetSites().SingleOrDefault(a => a.Id == site.SiteId) == null) { site.SiteId = 0; } ISite _site = _resp.CreateSite(site.SiteId, site.Name); //todo: clone TExtensions.CloneData(_site, site); return(_site.Save()); }
public IEnumerable <ExtendFieldDto> GetExtendFields(int siteId) { ISite site = this._resp.GetSiteById(siteId); ExtendFieldDto dto; IEnumerable <IExtendField> extends = site.Extend.GetAllExtends(); foreach (IExtendField extend in extends) { //todo: clone dto = TExtensions.CloneData(new ExtendFieldDto(), extend); dto.Id = extend.Id; yield return(dto); } }
public int SaveExtendField(int siteId, ExtendFieldDto dto) { ISite site = this._resp.GetSiteById(siteId); if (site == null) { throw new Exception("站点不存在"); } IExtendField field = this._extendResp.CreateExtendField(dto.Id, dto.Name); //todo: clone TExtensions.CloneData(field, dto); return(site.Extend.SaveExtendField(field)); }
private static Variance enumerableCompare <T>(T val1, T val2, string fieldName) { return(typeof(IEnumerable <>).IsAssignableFrom(typeof(T)) ? TExtensions.homogeneousEnumerableCompare <T>(val1, val2, fieldName) : TExtensions.heterogeneousEnumerableCompare <T>(val1, val2, fieldName)); }