Beispiel #1
0
        public static IPropertyAccessor GetPropertyAccessor(Type type, string propertyName)
        {
            Dictionary <string, IPropertyAccessor> propertyAccessors = null;
            IPropertyAccessor accessor = null;

            if (!cachedPropertyAccessors.TryGetValue(type, out propertyAccessors))
            {
                cachedPropertyAccessors[type] = propertyAccessors = new Dictionary <string, IPropertyAccessor>();
            }

            if (!propertyAccessors.TryGetValue(propertyName, out accessor))
            {
                var propertyInfo = type.GetPropertyReliable(propertyName);

                propertyAccessors[propertyName] = accessor = propertyInfo == null ? null : PropertyInfoHelper.GetAccessor(propertyInfo);
            }

            return(accessor);
        }
Beispiel #2
0
        public static IPropertyAccessor GetPropertyAccessor(Type type, string propertyName)
        {
            return("GetPropertyAccessor".Measure(() =>
            {
                if (!cachedPropertyAccessors.TryGetValue(type, out Dictionary <string, IPropertyAccessor> propertyAccessors))
                {
                    cachedPropertyAccessors[type] = propertyAccessors = new Dictionary <string, IPropertyAccessor>();
                }

                if (!propertyAccessors.TryGetValue(propertyName, out IPropertyAccessor accessor))
                {
                    var propertyInfo = type.GetRuntimeProperty(propertyName);

                    propertyAccessors[propertyName] = accessor = propertyInfo == null ? null : PropertyInfoHelper.GetAccessor(propertyInfo);
                }

                return accessor;
            }));
        }