private Dictionary <string, object> GetKeyValueDictSync <TDict, TKey>(List <TDict> keyValueList, Expression <Func <TDict, TKey> > keyProperty) { var keyPropertyName = PropertyLambda.For(keyProperty); var keyPropertyInfo = typeof(TDict).GetProperty(keyPropertyName); var cacheKey = string.Format("{0}.{1}", typeof(TDict).FullName, keyPropertyName); if (!this.KeyValueCacheDict.ContainsKey(cacheKey)) { lock (syncObj) { if (!this.KeyValueCacheDict.ContainsKey(cacheKey)) { Dictionary <string, object> keyValueDict = new Dictionary <string, object>(); foreach (var item in keyValueList) { var keyItem = keyPropertyInfo.GetValue(item, null); var keyString = keyItem == null ? string.Empty : keyItem.ToString().TrimOrEmpty(); if (!keyValueDict.ContainsKey(keyString)) { keyValueDict.Add(keyString, item); } } this.KeyValueCacheDict.Add(cacheKey, keyValueDict); } } } return(this.KeyValueCacheDict[cacheKey]); }
public static string PropertyName <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression) { return(PropertyLambda.For(expression)); }