public static TypeTracker GetTypeTracker(Type type) { TypeTracker res; lock (_typeCache) { if (!_typeCache.TryGetValue(type, out res)) { _typeCache[type] = res = new NestedTypeTracker(type); } } return(res); }
/// <param name="existingTypeEntity">The merged list so far. Could be null</param> /// <param name="newType">The new type(s) to add to the merged list</param> /// <returns>The merged list. Could be a TypeTracker or TypeGroup</returns> public static TypeTracker UpdateTypeEntity( TypeTracker existingTypeEntity, TypeTracker newType) { Debug.Assert(newType != null); Debug.Assert(existingTypeEntity == null || (existingTypeEntity is NestedTypeTracker) || (existingTypeEntity is TypeGroup)); if (existingTypeEntity == null) { return(newType); } NestedTypeTracker existingType = existingTypeEntity as NestedTypeTracker; TypeGroup existingTypeCollision = existingTypeEntity as TypeGroup; #if DEBUG string existingEntityNormalizedName = (existingType != null) ? ReflectionUtils.GetNormalizedTypeName(existingType.Type) : existingTypeCollision.NormalizedName; string newEntityNormalizedName = ReflectionUtils.GetNormalizedTypeName(newType.Type); Debug.Assert(existingEntityNormalizedName == newEntityNormalizedName); #endif if (existingType != null) { if (GetGenericArity(existingType.Type) == GetGenericArity(newType.Type)) { return(newType); } return(new TypeGroup(existingType.Type, newType.Type)); } // copy the dictionary and return a new collision Dictionary <int, Type> copy = new Dictionary <int, Type>(existingTypeCollision._typesByArity); return(new TypeGroup(newType.Type, copy)); }