示例#1
0
        /// <summary>
        /// Creates a new instance of the safe property wrapper.
        /// </summary>
        /// <param name="propertyInfo">Property to wrap.</param>
        public SafeProperty(PropertyInfo propertyInfo)
        {
            AssertUtils.ArgumentNotNull(propertyInfo, "You cannot create a dynamic property for a null value.");

            this.propertyInfo = propertyInfo;
            DynamicPropertyCacheEntry pi = GetOrCreateDynamicProperty(propertyInfo);

            getter = pi.Getter;
            setter = pi.Setter;
        }
        /// <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);
        }
示例#3
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);
        }
示例#4
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;
 }