protected PropertyAccessor GetAccessor(object x, string propertyName)
        {
            var type  = x.GetType();
            var props = propertyAccessorStore.GetOrAdd(type, (key) =>
                                                       useConcurrentDictionary ?
                                                       (ISafeDictionary <string, PropertyAccessor>)(new SafeConcurrentDictionary <string, PropertyAccessor>(StringComparer.InvariantCulture))
                    :
                                                       (ISafeDictionary <string, PropertyAccessor>)(new SafeDictionary <string, PropertyAccessor>(StringComparer.InvariantCulture))
                                                       );

            return(props.GetOrAdd(propertyName, (key) =>
                                  new PropertyAccessor(GlobalPropertyBuilder.GetReader(type, propertyName, StringComparison.InvariantCulture),
                                                       GlobalPropertyBuilder.GetWriter(type, propertyName, StringComparison.InvariantCulture))));
        }
Example #2
0
        public List <PropertyInfo> GetProperties(Type type, BindingFlags attrs, Func <PropertyInfo, bool> predicate = null)
        {
            var props = propStore.GetOrAdd(type, (t) =>
                                           useConcurrentDictionary ?
                                           (ISafeDictionary <BindingFlags, List <PropertyInfo> >)(new SafeConcurrentDictionary <BindingFlags, List <PropertyInfo> >())
                    :
                                           (ISafeDictionary <BindingFlags, List <PropertyInfo> >)(new SafeDictionary <BindingFlags, List <PropertyInfo> >())
                                           );

            var result = props.GetOrAdd(attrs, (a) => type.GetProperties(attrs).ToList());

            if (predicate != null)
            {
                result = result.Where(predicate).ToList();
            }

            return(result ?? new List <PropertyInfo>());
        }