Exemple #1
0
        /// <summary>
        /// Obtains cached property info or creates a new entry, if none is found.
        /// </summary>
        private static DynamicPropertyCacheEntry GetOrCreateDynamicProperty(PropertyInfo property)
        {
            DynamicPropertyCacheEntry propertyInfo;

            if (!propertyCache.TryGetValue(property, out propertyInfo))
            {
                propertyInfo = new DynamicPropertyCacheEntry(DynamicReflectionManager.CreatePropertyGetter(property), DynamicReflectionManager.CreatePropertySetter(property));
                lock (propertyCache)
                {
                    propertyCache[property] = propertyInfo;
                }
            }
            return(propertyInfo);
        }
        /// <summary>
        /// Obtains cached constructor info or creates a new entry, if none is found.
        /// </summary>
        private static ConstructorDelegate GetOrCreateDynamicConstructor(ConstructorInfo constructorInfo)
        {
            ConstructorDelegate method;

            if (!constructorCache.TryGetValue(constructorInfo, out method))
            {
                method = DynamicReflectionManager.CreateConstructor(constructorInfo);
                lock (constructorCache)
                {
                    constructorCache[constructorInfo] = method;
                }
            }
            return(method);
        }
Exemple #3
0
        /// <summary>
        /// Obtains cached fieldInfo or creates a new entry, if none is found.
        /// </summary>
        private static DynamicFieldCacheEntry GetOrCreateDynamicField(FieldInfo field)
        {
            DynamicFieldCacheEntry fieldInfo;

            if (!fieldCache.TryGetValue(field, out fieldInfo))
            {
                fieldInfo = new DynamicFieldCacheEntry(DynamicReflectionManager.CreateFieldGetter(field), DynamicReflectionManager.CreateFieldSetter(field));
                lock (fieldCache)
                {
                    fieldCache[field] = fieldInfo;
                }
            }
            return(fieldInfo);
        }
Exemple #4
0
        /// <summary>
        /// Creates a new instance of the safe method wrapper.
        /// </summary>
        /// <param name="methodInfo">Method to wrap.</param>
        public SafeMethod(MethodInfo methodInfo)
        {
            AssertUtils.ArgumentNotNull(methodInfo, "You cannot create a dynamic method for a null value.");

            state = (SafeMethodState)stateCache[methodInfo];
            if (state == null)
            {
                state = new SafeMethodState(DynamicReflectionManager.CreateMethod(methodInfo),
                                            new object[methodInfo.GetParameters().Length]
                                            );
                stateCache[methodInfo] = state;
            }
            this.methodInfo = methodInfo;
        }
Exemple #5
0
        /// <summary>
        /// Obtains cached constructor info or creates a new entry, if none is found.
        /// </summary>
        private static ConstructorDelegate GetOrCreateDynamicConstructor(ConstructorInfo constructorInfo)
        {
            ConstructorDelegate method = (ConstructorDelegate)constructorCache[constructorInfo];

            if (method == null)
            {
                method = DynamicReflectionManager.CreateConstructor(constructorInfo);
                lock (constructorCache)
                {
                    constructorCache[constructorInfo] = method;
                }
            }
            return(method);
        }
Exemple #6
0
        /// <summary>
        /// Obtains cached fieldInfo or creates a new entry, if none is found.
        /// </summary>
        private static DynamicFieldCacheEntry GetOrCreateDynamicField(FieldInfo field)
        {
            DynamicFieldCacheEntry fieldInfo = (DynamicFieldCacheEntry)fieldCache[field];

            if (fieldInfo == null)
            {
                fieldInfo = new DynamicFieldCacheEntry(DynamicReflectionManager.CreateFieldGetter(field), DynamicReflectionManager.CreateFieldSetter(field));
                lock (fieldCache)
                {
                    fieldCache[field] = fieldInfo;
                }
            }
            return(fieldInfo);
        }
        /// <summary>
        /// Obtains cached property info or creates a new entry, if none is found.
        /// </summary>
        private static DynamicPropertyCacheEntry GetOrCreateDynamicProperty(PropertyInfo property)
        {
            DynamicPropertyCacheEntry propertyInfo = (DynamicPropertyCacheEntry)propertyCache[property];

            if (propertyInfo == null)
            {
                propertyInfo = new DynamicPropertyCacheEntry(DynamicReflectionManager.CreatePropertyGetter(property), DynamicReflectionManager.CreatePropertySetter(property));
                lock (propertyCache)
                {
                    propertyCache[property] = propertyInfo;
                }
            }
            return(propertyInfo);
        }