public override int GetHashCode() {
     HashCodeCombiner hashCodeCombiner = new HashCodeCombiner();
     hashCodeCombiner.AddObject(_varyByAllParams);
     
     // Cast _varyByCustom to an object, since the HashCodeCombiner.AddObject(string)
     // overload uses StringUtil.GetStringHashCode().  We want to use String.GetHashCode()
     // in this method, since we do not require a stable hash code across architectures.
     hashCodeCombiner.AddObject((object)_varyByCustom);
     
     hashCodeCombiner.AddArray(_contentEncodings);
     hashCodeCombiner.AddArray(_headers);
     hashCodeCombiner.AddArray(_params);
     return hashCodeCombiner.CombinedHash32;
 }
 internal static string GetDirectoryHash(VirtualPath virtualDir) {
     HashCodeCombiner hashCodeCombiner = new HashCodeCombiner();
     hashCodeCombiner.AddDirectory(virtualDir.MapPathInternal());
     return hashCodeCombiner.CombinedHashString;
 }
 public override int GetHashCode() {
     // This implementation of GetHashCode uses mutable properties but matches the V1 implementation
     // of Equals.
     HashCodeCombiner hashCodeCombiner = new HashCodeCombiner();
     foreach (DictionaryEntry attr in _bag) {
         hashCodeCombiner.AddObject(attr.Key);
         hashCodeCombiner.AddObject(attr.Value);
     }
     return hashCodeCombiner.CombinedHash32;
 }
Esempio n. 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);
        }
 public override int GetHashCode()
 {
     return(HashCodeCombiner.CombineHashCodes(LastWriteTime.GetHashCode(), Size.GetHashCode()));
 }
 internal static string GetDirectoryHash(VirtualPath virtualDir)
 {
     HashCodeCombiner combiner = new HashCodeCombiner();
     combiner.AddDirectory(virtualDir.MapPathInternal());
     return combiner.CombinedHashString;
 }