Esempio n. 1
0
        public Action <object, TProperty> GetPropertySetter <TProperty>(
            PropertyInfo propertyInfo,
            DelegateCreationMode creationMode)
        {
            var dictionary = setterGenericDictionary;

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

                default:
                    var setMethod = propertyInfo.SetMethod;
                    result = new Action <object, TProperty>(
                        (owner, newValue) => setMethod.Invoke(owner, new object[] { newValue }));
                    break;
                }

                dictionary[propertyInfo] = result;
            }

            return((Action <object, TProperty>)result);
        }
Esempio n. 2
0
        public Action <object, object> GetPropertySetter(
            PropertyInfo propertyInfo)
        {
            Action <object, object> setter;

            var lockSlim   = setterLockSlim;
            var dictionary = setterDictionary;

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

            return(setter);
        }
Esempio n. 3
0
        public Action <object, object> GetPropertySetter(
            PropertyInfo propertyInfo,
            DelegateCreationMode creationMode)
        {
            var dictionary = setterDictionary;

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

                default:
                    var setMethod = propertyInfo.SetMethod;
                    setter = (owner, newValue) => setMethod.Invoke(owner, new [] { newValue });
                    break;
                }

                dictionary[propertyInfo] = setter;
            }

            return(setter);
        }
Esempio n. 4
0
        public Action <object, TProperty> GetPropertySetter <TProperty>(
            PropertyInfo propertyInfo)
        {
            object setter;

            var lockSlim   = setterGenericLockSlim;
            var dictionary = setterGenericDictionary;

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

            return((Action <object, TProperty>)setter);
        }