private static IWebPropertyAccessor GetPropertyAccessor(Type type, string propertyName)
        {
            if ((s_accessorGenerator == null) || (s_accessorCache == null))
            {
                lock (s_lockObject)
                {
                    if ((s_accessorGenerator == null) || (s_accessorCache == null))
                    {
                        s_accessorGenerator = new FastPropertyAccessor();
                        s_accessorCache     = new Hashtable();
                    }
                }
            }
            int num = HashCodeCombiner.CombineHashCodes(type.GetHashCode(), propertyName.GetHashCode());
            IWebPropertyAccessor accessor = (IWebPropertyAccessor)s_accessorCache[num];

            if (accessor == null)
            {
                Type         type2;
                FieldInfo    fieldInfo = null;
                PropertyInfo propInfo  = null;
                GetPropertyInfo(type, propertyName, out propInfo, out fieldInfo, out type2);
                int num2 = 0;
                if (type2 != type)
                {
                    num2     = HashCodeCombiner.CombineHashCodes(type2.GetHashCode(), propertyName.GetHashCode());
                    accessor = (IWebPropertyAccessor)s_accessorCache[num2];
                    if (accessor != null)
                    {
                        lock (s_accessorCache.SyncRoot)
                        {
                            s_accessorCache[num] = accessor;
                        }
                        return(accessor);
                    }
                }
                if (accessor == null)
                {
                    Type type3;
                    lock (s_accessorGenerator)
                    {
                        type3 = s_accessorGenerator.GetPropertyAccessorTypeWithAssert(type2, propertyName, propInfo, fieldInfo);
                    }
                    accessor = (IWebPropertyAccessor)HttpRuntime.CreateNonPublicInstance(type3);
                }
                lock (s_accessorCache.SyncRoot)
                {
                    s_accessorCache[num] = accessor;
                    if (num2 != 0)
                    {
                        s_accessorCache[num2] = accessor;
                    }
                }
            }
            return(accessor);
        }
 private static IWebPropertyAccessor GetPropertyAccessor(Type type, string propertyName)
 {
     if ((s_accessorGenerator == null) || (s_accessorCache == null))
     {
         lock (s_lockObject)
         {
             if ((s_accessorGenerator == null) || (s_accessorCache == null))
             {
                 s_accessorGenerator = new FastPropertyAccessor();
                 s_accessorCache = new Hashtable();
             }
         }
     }
     int num = HashCodeCombiner.CombineHashCodes(type.GetHashCode(), propertyName.GetHashCode());
     IWebPropertyAccessor accessor = (IWebPropertyAccessor) s_accessorCache[num];
     if (accessor == null)
     {
         Type type2;
         FieldInfo fieldInfo = null;
         PropertyInfo propInfo = null;
         GetPropertyInfo(type, propertyName, out propInfo, out fieldInfo, out type2);
         int num2 = 0;
         if (type2 != type)
         {
             num2 = HashCodeCombiner.CombineHashCodes(type2.GetHashCode(), propertyName.GetHashCode());
             accessor = (IWebPropertyAccessor) s_accessorCache[num2];
             if (accessor != null)
             {
                 lock (s_accessorCache.SyncRoot)
                 {
                     s_accessorCache[num] = accessor;
                 }
                 return accessor;
             }
         }
         if (accessor == null)
         {
             Type type3;
             lock (s_accessorGenerator)
             {
                 type3 = s_accessorGenerator.GetPropertyAccessorTypeWithAssert(type2, propertyName, propInfo, fieldInfo);
             }
             accessor = (IWebPropertyAccessor) HttpRuntime.CreateNonPublicInstance(type3);
         }
         lock (s_accessorCache.SyncRoot)
         {
             s_accessorCache[num] = accessor;
             if (num2 != 0)
             {
                 s_accessorCache[num2] = accessor;
             }
         }
     }
     return accessor;
 }
        private static IWebPropertyAccessor GetPropertyAccessor(Type type, string propertyName) {

            if (s_accessorGenerator == null || s_accessorCache == null) {
                lock (s_lockObject) {
                    if (s_accessorGenerator == null || s_accessorCache == null) {
                        s_accessorGenerator = new FastPropertyAccessor();
                        s_accessorCache = new Hashtable();
                    }
                }
            }

            // First, check if we have it cached

            // Get a hash key based on the Type and the property name
            int cacheKey = HashCodeCombiner.CombineHashCodes(
                type.GetHashCode(), propertyName.GetHashCode());

            IWebPropertyAccessor accessor = (IWebPropertyAccessor)s_accessorCache[cacheKey];

            // It was cached, so just return it
            if (accessor != null)
                return accessor;

            FieldInfo fieldInfo = null;
            PropertyInfo propInfo = null;
            Type declaringType;

            GetPropertyInfo(type, propertyName, out propInfo, out fieldInfo, out declaringType);

            // If the Type where the property/field is declared is not the same as the current
            // Type, check if the declaring Type already has a cached accessor.  This limits
            // the number of different accessors we need to create.  e.g. Every control has
            // an ID property, but we'll end up only create one accessor for all of them.
            int declaringTypeCacheKey = 0;
            if (declaringType != type) {
                // Get a hash key based on the declaring Type and the property name
                declaringTypeCacheKey = HashCodeCombiner.CombineHashCodes(
                    declaringType.GetHashCode(), propertyName.GetHashCode());

                accessor = (IWebPropertyAccessor) s_accessorCache[declaringTypeCacheKey];

                // We have a cached accessor for the declaring type, so use it
                if (accessor != null) {

                    // Cache the declaring type's accessor as ourselves
                    lock (s_accessorCache.SyncRoot) {
                        s_accessorCache[cacheKey] = accessor;
                    }

                    return accessor;
                }
            }

            if (accessor == null) {
                Type propertyAccessorType;

                lock (s_accessorGenerator) {
                    propertyAccessorType = s_accessorGenerator.GetPropertyAccessorTypeWithAssert(
                        declaringType, propertyName, propInfo, fieldInfo);
                }

                // Create the type. This is the only place where Activator.CreateInstance is used,
                // reducing the calls to it from 1 per instance to 1 per type.
                accessor = (IWebPropertyAccessor) HttpRuntime.CreateNonPublicInstance(propertyAccessorType);
            }

            // Cache the accessor
            lock (s_accessorCache.SyncRoot) {
                s_accessorCache[cacheKey] = accessor;

                if (declaringTypeCacheKey != 0)
                    s_accessorCache[declaringTypeCacheKey] = accessor;
            }

            return accessor;
        }
Example #4
0
        private static IWebPropertyAccessor GetPropertyAccessor(Type type, string propertyName)
        {
            if (s_accessorGenerator == null || s_accessorCache == null)
            {
                lock (s_lockObject) {
                    if (s_accessorGenerator == null || s_accessorCache == null)
                    {
                        s_accessorGenerator = new FastPropertyAccessor();
                        s_accessorCache     = new Hashtable();
                    }
                }
            }

            // First, check if we have it cached

            // Get a hash key based on the Type and the property name
            int cacheKey = HashCodeCombiner.CombineHashCodes(
                type.GetHashCode(), propertyName.GetHashCode());

            IWebPropertyAccessor accessor = (IWebPropertyAccessor)s_accessorCache[cacheKey];

            // It was cached, so just return it
            if (accessor != null)
            {
                return(accessor);
            }

            FieldInfo    fieldInfo = null;
            PropertyInfo propInfo  = null;
            Type         declaringType;

            GetPropertyInfo(type, propertyName, out propInfo, out fieldInfo, out declaringType);

            // If the Type where the property/field is declared is not the same as the current
            // Type, check if the declaring Type already has a cached accessor.  This limits
            // the number of different accessors we need to create.  e.g. Every control has
            // an ID property, but we'll end up only create one accessor for all of them.
            int declaringTypeCacheKey = 0;

            if (declaringType != type)
            {
                // Get a hash key based on the declaring Type and the property name
                declaringTypeCacheKey = HashCodeCombiner.CombineHashCodes(
                    declaringType.GetHashCode(), propertyName.GetHashCode());

                accessor = (IWebPropertyAccessor)s_accessorCache[declaringTypeCacheKey];

                // We have a cached accessor for the declaring type, so use it
                if (accessor != null)
                {
                    // Cache the declaring type's accessor as ourselves
                    lock (s_accessorCache.SyncRoot) {
                        s_accessorCache[cacheKey] = accessor;
                    }

                    return(accessor);
                }
            }

            if (accessor == null)
            {
                Type propertyAccessorType;

                lock (s_accessorGenerator) {
                    propertyAccessorType = s_accessorGenerator.GetPropertyAccessorTypeWithAssert(
                        declaringType, propertyName, propInfo, fieldInfo);
                }

                // Create the type. This is the only place where Activator.CreateInstance is used,
                // reducing the calls to it from 1 per instance to 1 per type.
                accessor = (IWebPropertyAccessor)HttpRuntime.CreateNonPublicInstance(propertyAccessorType);
            }

            // Cache the accessor
            lock (s_accessorCache.SyncRoot) {
                s_accessorCache[cacheKey] = accessor;

                if (declaringTypeCacheKey != 0)
                {
                    s_accessorCache[declaringTypeCacheKey] = accessor;
                }
            }

            return(accessor);
        }