public static ConcurrentDictionary <PropertyInfo, Func <object, object> > GetterDelegatesByPropertyInfo(Type type) { if (!GetterDelegatesByPropertyInfoCache.ContainsKey(type)) { GetterDelegatesByPropertyInfoCache[type] = new ConcurrentDictionary <PropertyInfo, Func <object, object> >(); } foreach (var propertyInfo in PropertiesInfo(type)) { GetterDelegatesByPropertyInfoCache[type][propertyInfo] = DelegateGenerator.GetDelegate(propertyInfo); } return(GetterDelegatesByPropertyInfoCache[type]); }
public static ConcurrentDictionary <string, Func <object, object> > GetterDelegatesByPropertyName(Type type, Case toCase = Case.Default) { if (!GetterDelegatesByPropertyNameCache.ContainsKey(type)) { GetterDelegatesByPropertyNameCache[type] = new ConcurrentDictionary <Case, ConcurrentDictionary <string, Func <object, object> > >(); } if (!GetterDelegatesByPropertyNameCache[type].ContainsKey(toCase)) { GetterDelegatesByPropertyNameCache[type][toCase] = new ConcurrentDictionary <string, Func <object, object> >(); foreach (var propertyInfo in PropertiesInfo(type)) { var name = propertyInfo.Name; switch (toCase) { case Case.Snake: name = name.ToSnakeCase(); break; case Case.Camel: name = name.ToCamelCase(); break; case Case.Pascal: name = name.ToPascalCase(); break; case Case.Default: break; default: throw new ArgumentOutOfRangeException(nameof(toCase), toCase, null); } GetterDelegatesByPropertyNameCache[type][toCase][name] = DelegateGenerator.GetDelegate(propertyInfo); } } return(GetterDelegatesByPropertyNameCache[type][toCase]); }
private static IEnumerable <PropertyMapper> PropertyMappers(Type type) { if (!cache.ContainsKey(type)) { cache[type] = type.GetProperties().Select(propertyInfo => new PropertyMapper(propertyInfo, DelegateGenerator.GetDelegate(propertyInfo), DelegateGenerator.SetDelegate(propertyInfo))).ToArray(); } return(cache[type]); }