Esempio n. 1
0
        /* The Get* methods in this class are deliberately more verbose
         * than they need to be. We could remove the duplication within
         * each code block, however the code needs to be fast,
         * and the overhead of creating an Action for each call
         * would not be worth it. */

        public Func <object, object> GetPropertyGetter(
            PropertyInfo propertyInfo)
        {
            Func <object, object> getter;

            var lockSlim   = getterLockSlim;
            var dictionary = getterGenericDictionary;

            lockSlim.EnterUpgradeableReadLock();
            try
            {
                if (!dictionary.TryGetValue(propertyInfo, out getter))
                {
                    lockSlim.EnterWriteLock();
                    try
                    {
                        if (!dictionary.TryGetValue(propertyInfo, out getter))
                        {
                            getter = ReflectionCompiler.CreatePropertyGetter(propertyInfo);
                            dictionary[propertyInfo] = getter;
                        }
                    }
                    finally
                    {
                        lockSlim.ExitWriteLock();
                    }
                }
            }
            finally
            {
                lockSlim.ExitUpgradeableReadLock();
            }

            return(getter);
        }
Esempio n. 2
0
        public Func <object, TProperty> GetPropertyGetter <TProperty>(
            PropertyInfo propertyInfo,
            DelegateCreationMode creationMode)
        {
            Func <object, TProperty> result;

            var dictionary = getterDictionary;

            if (!dictionary.TryGetValue(propertyInfo, out object getter))
            {
                switch (creationMode)
                {
                case DelegateCreationMode.SlowCreationFastPerformance:
                    result = ReflectionCompiler.CreatePropertyGetter <TProperty>(propertyInfo);
                    break;

                default:
                    var getMethod = propertyInfo.GetMethod;
                    result = owner => (TProperty)getMethod.Invoke(owner, null);
                    break;
                }

                dictionary[propertyInfo] = result;
                return(result);
            }

            result = (Func <object, TProperty>)getter;
            return(result);
        }
Esempio n. 3
0
        public Func <TOwner, TProperty> GetPropertyGetter <TOwner, TProperty>(
            Expression <Func <TOwner, TProperty> > propertyExpression)
        {
            /* TODO: extract property name and cache item in dictionary. */
            Func <TOwner, TProperty> result = ReflectionCompiler.CreatePropertyGetter(propertyExpression);

            return(result);
        }
Esempio n. 4
0
        public Func <object, TProperty> GetPropertyGetter <TProperty>(
            PropertyInfo propertyInfo)
        {
            Func <object, TProperty> result;
            object getter;

            var lockSlim   = getterGenericLockSlim;
            var dictionary = getterDictionary;

            lockSlim.EnterUpgradeableReadLock();
            try
            {
                if (!dictionary.TryGetValue(propertyInfo, out getter))
                {
                    lockSlim.EnterWriteLock();
                    try
                    {
                        if (!dictionary.TryGetValue(propertyInfo, out getter))
                        {
                            result = ReflectionCompiler.CreatePropertyGetter <TProperty>(propertyInfo);
                            dictionary[propertyInfo] = result;
                            return(result);
                        }
                    }
                    finally
                    {
                        lockSlim.ExitWriteLock();
                    }
                }
            }
            finally
            {
                lockSlim.ExitUpgradeableReadLock();
            }

            result = (Func <object, TProperty>)getter;
            return(result);
        }
Esempio n. 5
0
        /* The Get* methods in this class are deliberately more verbose
         * than they need to be. We could remove the duplication within
         * each code block, however the code needs to be fast,
         * and the overhead of creating an Action for each call
         * would not be worth it. */

        public Func <object, object> GetPropertyGetter(
            PropertyInfo propertyInfo,
            DelegateCreationMode creationMode)
        {
            var dictionary = getterGenericDictionary;

            if (!dictionary.TryGetValue(propertyInfo, out var getter))
            {
                switch (creationMode)
                {
                case DelegateCreationMode.SlowCreationFastPerformance:
                    getter = ReflectionCompiler.CreatePropertyGetter(propertyInfo);
                    break;

                default:
                    getter = propertyInfo.GetValue;
                    break;
                }

                dictionary[propertyInfo] = getter;
            }

            return(getter);
        }