/// <summary> /// Lookups the set. /// </summary> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="propertySelector">The property selector.</param> /// <param name="propertyName">Name of the property.</param> /// <returns></returns> public static Action <TType, TProperty> LookupSet <TProperty>(Expression <Func <TType, TProperty> > propertySelector, out string propertyName) { propertyName = ExpressionTreeUtils.GetPropertyName(propertySelector); Delegate accessor; lock (s_setCache) { if (!s_setCache.TryGetValue(propertyName, out accessor)) { accessor = CreateSetAccessor(propertySelector); s_setCache.Add(propertyName, accessor); } } return((Action <TType, TProperty>)accessor); }
/// <summary> /// Lookups the get. /// </summary> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="propertySelector">The property selector.</param> /// <param name="propertyName">Name of the property.</param> /// <returns></returns> public static Func <TType, TProperty> LookupNestedGet <TProperty>(Expression <Func <TType, TProperty> > propertySelector, out string propertyName) { propertyName = ExpressionTreeUtils.GetPropertyPath(propertySelector); Delegate accessor; lock (s_getCache) { if (!s_getCache.TryGetValue(propertyName, out accessor)) { accessor = propertySelector.Compile(); s_getCache.Add(propertyName, accessor); } } return((Func <TType, TProperty>)accessor); }